	import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.Stack;
import java.util.TreeSet;
		public class Main implements Runnable
		{
			static final long MOD = 1000000007L;
			static final long MOD2 = 1000000009L;
			static class InputReader
			{
				private InputStream stream;
				private byte[] buf = new byte[1024];
				private int curChar;
				private int numChars;
				private SpaceCharFilter filter;
				private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

				public InputReader(InputStream stream)
				{
					this.stream = stream;
				}

				public int read()
				{
					if (numChars==-1)
						throw new InputMismatchException();

					if (curChar >= numChars)
					{
						curChar = 0;
						try
						{
							numChars = stream.read(buf);
						}
						catch (IOException e)
						{
							throw new InputMismatchException();
						}

						if(numChars <= 0)
							return -1;
					}
					return buf[curChar++];
				}

				public String nextLine()
				{
					String str = "";
		            try
		            {
		                str = br.readLine();
		            }
		            catch (IOException e)
		            {
		                e.printStackTrace();
		            }
		            return str;
				}
				public int nextInt()
				{
					int c = read();

					while(isSpaceChar(c))
						c = read();

					int sgn = 1;

					if (c == '-')
					{
						sgn = -1;
						c = read();
					}

					int res = 0;
					do
					{
						if(c<'0'||c>'9')
							throw new InputMismatchException();
						res *= 10;
						res += c - '0';
						c = read();
					}
					while (!isSpaceChar(c));

					return res * sgn;
				}

				public long nextLong()
				{
					int c = read();
					while (isSpaceChar(c))
						c = read();
					int sgn = 1;
					if (c == '-')
					{
						sgn = -1;
						c = read();
					}
					long res = 0;

					do
					{
						if (c < '0' || c > '9')
							throw new InputMismatchException();
						res *= 10;
						res += c - '0';
						c = read();
					}
					while (!isSpaceChar(c));
						return res * sgn;
				}

				public double nextDouble()
				{
					int c = read();
					while (isSpaceChar(c))
						c = read();
					int sgn = 1;
					if (c == '-')
					{
						sgn = -1;
						c = read();
					}
					double res = 0;
					while (!isSpaceChar(c) && c != '.')
					{
						if (c == 'e' || c == 'E')
							return res * Math.pow(10, nextInt());
						if (c < '0' || c > '9')
							throw new InputMismatchException();
						res *= 10;
						res += c - '0';
						c = read();
					}
					if (c == '.')
					{
						c = read();
						double m = 1;
						while (!isSpaceChar(c))
						{
							if (c == 'e' || c == 'E')
								return res * Math.pow(10, nextInt());
							if (c < '0' || c > '9')
								throw new InputMismatchException();
							m /= 10;
							res += (c - '0') * m;
							c = read();
						}
					}
					return res * sgn;
				}

				public String readString()
				{
					int c = read();
					while (isSpaceChar(c))
						c = read();
					StringBuilder res = new StringBuilder();
					do
					{
						res.appendCodePoint(c);
						c = read();
					}
					while (!isSpaceChar(c));

					return res.toString();
				}

				public boolean isSpaceChar(int c)
				{
					if (filter != null)
						return filter.isSpaceChar(c);
					return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
				}

				public String next()
				{
					return readString();
				}

				public interface SpaceCharFilter
				{
					public boolean isSpaceChar(int ch);
				}
			}

			public static void main(String args[]) throws Exception
			{
				new Thread(null, new Main(),"Main",1<<26).start();
			}
			int MAXN = 1000001;
			public void run()
			{
				InputReader sc= new InputReader(System.in);
				PrintWriter w= new PrintWriter(System.out);
				String s = sc.next();
				Temp[] ans = new Temp[s.length()];
				double l = 0;
				double r = 1;
				for(int i = 0;i < s.length();i++) {
					double mid = (l + r)/2;
					if(s.charAt(i) == 'l') {
						r = mid;
					}else {
						l = mid;
					}
					ans[i] = new Temp(mid,i);
				}
				Arrays.sort(ans);
				long[] fans = new long[s.length()];
				for(int i = 0;i < ans.length;i++) {
					fans[i] = ans[i].b;
				}
				for(int i = 0;i < ans.length;i++) {
					w.println(fans[i]+1);
				}
				w.close();
			}

			static boolean isPrime(long n)
		    {
		        // Corner cases
		        if (n <= 1) return false;
		        if (n <= 3) return true;

		        // This is checked so that we can skip
		        // middle five numbers in below loop
		        if (n % 2 == 0 || n % 3 == 0) return false;

		        for (int i = 5; i * i <= n; i = i + 6)
		            if (n % i == 0 || n % (i + 2) == 0)
		            return false;

		        return true;
		    }

			long count = 0;
			long[][] dist;
			void flydwarShall(int k,int size) {
				for(int i = 0;i < size;i++) {
					for(int j = 0;j < size;j++) {
						if(dist[i][j] > dist[i][k] + dist[k][j]) {
							dist[i][j] = dist[i][k] + dist[k][j];
						}
					}
				}
			}
			Pair[] segTree;
			int[] arr;
			void build(int l,int r,int pos) {
				if(l == r) {
					segTree[pos] = new Pair(1,1,1,arr[l],arr[l],true);
					return;
				}
				int mid = (l + r) >> 1;
				build(l,mid,2*pos+1);
				build(mid+1, r, 2*pos+2);
				segTree[pos] = merge(segTree[2*pos+1], segTree[2*pos+2]);
			}
			Pair merge(Pair p1,Pair p2) {
				if(p1.val1 == 0) {
					return p2;
				}else if(p2.val1 == 0) {
					return p1;
				}
				Pair navi = new Pair();
				navi.val1 = p1.val1;
				navi.val2 = p2.val2;
				if(p1.val2 == p2.val1) {
					navi.max = Math.max(p1.max,p2.max);
					navi.first = p1.first;
					navi.second = p2.second;
					navi.whole = false;
				}else {
					navi.max = Math.max(p1.max,Math.max(p2.max,p1.second + p2.first));
					if(p1.whole && p2.whole) {
						navi.first = p1.first + p2.first;
						navi.second = p1.first + p2.first;
						navi.whole = true;
					}else if(p1.whole) {
						navi.first = p1.first + p2.first;
						navi.second = p2.second;
						navi.whole = false;
					}else if(p2.whole) {
						navi.first = p1.first;
						navi.second = p1.second + p2.first;
						navi.whole = false;
					}else {
						navi.first = p1.first;
						navi.second = p2.second;
						navi.whole = false;
					}
				}
				return navi;
			}
			Pair query(int pos, int l, int r, int start, int end)
			{
			    if(end < l || r < start)
			    {
			        return new Pair(0,0,0,0,0,false);
			    }
			    if(start <= l && r <= end)
			    {
			        // range represented by a node is completely inside the given range
			        return segTree[pos];
			    }
			    // range represented by a node is partially inside and partially outside the given range
			    int mid = (l + r) / 2;
			    Pair p1 = query(2*pos + 1, l, mid, start, end);
			    Pair p2 = query(2*pos+2, mid+1, r, start, end);
			    return merge(p1, p2);
			}
			int bsearch(Integer[] arr,int l,int r,int val) {
				int ind = -1;
				while(l <= r) {
					int mid = (l + r)/2;
					if(arr[mid] <= val) {
						l = mid + 1;
						ind = mid;
					}else {
						r = mid - 1;
					}
				}
				return ind;
			}
			Stack<Integer> st = new Stack();
			int bridges = 0;

			long modExpo(long a,long pow,long mod) {
				long res = 1;
				while(pow > 0) {
					if(pow % 2 == 1) {
						res = (res * a) % mod;
					}
					pow = pow/2;
					a = (a * a) % mod;
				}
				return res;
			}
			  static long modInverse(long a, long m)
			    {

			            // If a and m are relatively prime, then modulo inverse
			            // is a^(m-2) mode m

			                        return        power(a, m - 2, m);

			    }

			    // To compute x^y under modulo m
			// Iterative Java program to
			// compute modular power

			    static long power(long x, long y,long p)
			    {
			        // Initialize result
			        long res = 1;

			        // Update x if it is more
			        // than or equal to p
			        x = x % p;

			        while (y > 0)
			        {
			            // If y is odd, multiply x
			            // with result
			            if((y & 1)==1)
			                res = (res * x) % p;

			            // y must be even now
			            // y = y / 2
			            y = y >> 1;
			            x = (x * x) % p;
			        }
			        return res;
			    }
			static class Temp implements Comparable<Temp>{
				double a;
				int b;
				Temp(double a,int b){
					this.a = a;
					this.b = b;
				}
				@Override
				public int compareTo(Temp t){
					return Double.compare(this.a,t.a);
				}
			}
			static class Pair implements Comparable<Pair>{
				int first;
				int max;
				int second;
				int val1;
				int val2;
				boolean whole;

				Pair (int a,int b,int c,int val1,int val2,boolean whole){
					this.first = a;
					this.max = b;
					this.second = c;
					this.val1= val1;
					this.val2 = val2;
					this.whole = whole;
				}
				Pair(){

				}
				public boolean equals(Object o)
				{
					Pair p = (Pair)o;
					return (p.first==first && p.max==max) || (p.first == max && p.first == max);
				}
				public int hashCode()
				{
					return new Long(first).hashCode()*31 + new Long(max).hashCode();
				}
				public int compareTo(Pair p){
					return Long.compare(p.first,this.first);
				}
			}

		}


	import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.Stack;
import java.util.TreeSet;
		public class Main implements Runnable
		{
			static final long MOD = 1000000007L;
			static final long MOD2 = 1000000009L;
			static class InputReader
			{
				private InputStream stream;
				private byte[] buf = new byte[1024];
				private int curChar;
				private int numChars;
				private SpaceCharFilter filter;
				private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

				public InputReader(InputStream stream)
				{
					this.stream = stream;
				}

				public int read()
				{
					if (numChars==-1)
						throw new InputMismatchException();

					if (curChar >= numChars)
					{
						curChar = 0;
						try
						{
							numChars = stream.read(buf);
						}
						catch (IOException e)
						{
							throw new InputMismatchException();
						}

						if(numChars <= 0)
							return -1;
					}
					return buf[curChar++];
				}

				public String nextLine()
				{
					String str = "";
		            try
		            {
		                str = br.readLine();
		            }
		            catch (IOException e)
		            {
		                e.printStackTrace();
		            }
		            return str;
				}
				public int nextInt()
				{
					int c = read();

					while(isSpaceChar(c))
						c = read();

					int sgn = 1;

					if (c == '-')
					{
						sgn = -1;
						c = read();
					}

					int res = 0;
					do
					{
						if(c<'0'||c>'9')
							throw new InputMismatchException();
						res *= 10;
						res += c - '0';
						c = read();
					}
					while (!isSpaceChar(c));

					return res * sgn;
				}

				public long nextLong()
				{
					int c = read();
					while (isSpaceChar(c))
						c = read();
					int sgn = 1;
					if (c == '-')
					{
						sgn = -1;
						c = read();
					}
					long res = 0;

					do
					{
						if (c < '0' || c > '9')
							throw new InputMismatchException();
						res *= 10;
						res += c - '0';
						c = read();
					}
					while (!isSpaceChar(c));
						return res * sgn;
				}

				public double nextDouble()
				{
					int c = read();
					while (isSpaceChar(c))
						c = read();
					int sgn = 1;
					if (c == '-')
					{
						sgn = -1;
						c = read();
					}
					double res = 0;
					while (!isSpaceChar(c) && c != '.')
					{
						if (c == 'e' || c == 'E')
							return res * Math.pow(10, nextInt());
						if (c < '0' || c > '9')
							throw new InputMismatchException();
						res *= 10;
						res += c - '0';
						c = read();
					}
					if (c == '.')
					{
						c = read();
						double m = 1;
						while (!isSpaceChar(c))
						{
							if (c == 'e' || c == 'E')
								return res * Math.pow(10, nextInt());
							if (c < '0' || c > '9')
								throw new InputMismatchException();
							m /= 10;
							res += (c - '0') * m;
							c = read();
						}
					}
					return res * sgn;
				}

				public String readString()
				{
					int c = read();
					while (isSpaceChar(c))
						c = read();
					StringBuilder res = new StringBuilder();
					do
					{
						res.appendCodePoint(c);
						c = read();
					}
					while (!isSpaceChar(c));

					return res.toString();
				}

				public boolean isSpaceChar(int c)
				{
					if (filter != null)
						return filter.isSpaceChar(c);
					return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
				}

				public String next()
				{
					return readString();
				}

				public interface SpaceCharFilter
				{
					public boolean isSpaceChar(int ch);
				}
			}

			public static void main(String args[]) throws Exception
			{
				new Thread(null, new Main(),"Main",1<<26).start();
			}
			int MAXN = 1000001;
			public void run()
			{
				InputReader sc= new InputReader(System.in);
				PrintWriter w= new PrintWriter(System.out);
				String s = sc.next();
				int[] ans = new int[s.length()+1];
				int l = 1;
				int r = s.length();
				for(int i = 0;i < s.length();i++) {
					if(s.charAt(i) == 'l') {
						r = r - 1;
						ans[r+1] = i+1;
					}else {
						l = l + 1;
						ans[l-1] = i+1;
					}

				}
				for(int i = 1;i < ans.length;i++) {
					w.println(ans[i]);
				}
				w.close();
			}

			static boolean isPrime(long n)
		    {
		        // Corner cases
		        if (n <= 1) return false;
		        if (n <= 3) return true;

		        // This is checked so that we can skip
		        // middle five numbers in below loop
		        if (n % 2 == 0 || n % 3 == 0) return false;

		        for (int i = 5; i * i <= n; i = i + 6)
		            if (n % i == 0 || n % (i + 2) == 0)
		            return false;

		        return true;
		    }

			long count = 0;
			long[][] dist;
			void flydwarShall(int k,int size) {
				for(int i = 0;i < size;i++) {
					for(int j = 0;j < size;j++) {
						if(dist[i][j] > dist[i][k] + dist[k][j]) {
							dist[i][j] = dist[i][k] + dist[k][j];
						}
					}
				}
			}
			Pair[] segTree;
			int[] arr;
			void build(int l,int r,int pos) {
				if(l == r) {
					segTree[pos] = new Pair(1,1,1,arr[l],arr[l],true);
					return;
				}
				int mid = (l + r) >> 1;
				build(l,mid,2*pos+1);
				build(mid+1, r, 2*pos+2);
				segTree[pos] = merge(segTree[2*pos+1], segTree[2*pos+2]);
			}
			Pair merge(Pair p1,Pair p2) {
				if(p1.val1 == 0) {
					return p2;
				}else if(p2.val1 == 0) {
					return p1;
				}
				Pair navi = new Pair();
				navi.val1 = p1.val1;
				navi.val2 = p2.val2;
				if(p1.val2 == p2.val1) {
					navi.max = Math.max(p1.max,p2.max);
					navi.first = p1.first;
					navi.second = p2.second;
					navi.whole = false;
				}else {
					navi.max = Math.max(p1.max,Math.max(p2.max,p1.second + p2.first));
					if(p1.whole && p2.whole) {
						navi.first = p1.first + p2.first;
						navi.second = p1.first + p2.first;
						navi.whole = true;
					}else if(p1.whole) {
						navi.first = p1.first + p2.first;
						navi.second = p2.second;
						navi.whole = false;
					}else if(p2.whole) {
						navi.first = p1.first;
						navi.second = p1.second + p2.first;
						navi.whole = false;
					}else {
						navi.first = p1.first;
						navi.second = p2.second;
						navi.whole = false;
					}
				}
				return navi;
			}
			Pair query(int pos, int l, int r, int start, int end)
			{
			    if(end < l || r < start)
			    {
			        return new Pair(0,0,0,0,0,false);
			    }
			    if(start <= l && r <= end)
			    {
			        // range represented by a node is completely inside the given range
			        return segTree[pos];
			    }
			    // range represented by a node is partially inside and partially outside the given range
			    int mid = (l + r) / 2;
			    Pair p1 = query(2*pos + 1, l, mid, start, end);
			    Pair p2 = query(2*pos+2, mid+1, r, start, end);
			    return merge(p1, p2);
			}
			int bsearch(Integer[] arr,int l,int r,int val) {
				int ind = -1;
				while(l <= r) {
					int mid = (l + r)/2;
					if(arr[mid] <= val) {
						l = mid + 1;
						ind = mid;
					}else {
						r = mid - 1;
					}
				}
				return ind;
			}
			Stack<Integer> st = new Stack();
			int bridges = 0;

			long modExpo(long a,long pow,long mod) {
				long res = 1;
				while(pow > 0) {
					if(pow % 2 == 1) {
						res = (res * a) % mod;
					}
					pow = pow/2;
					a = (a * a) % mod;
				}
				return res;
			}
			  static long modInverse(long a, long m)
			    {

			            // If a and m are relatively prime, then modulo inverse
			            // is a^(m-2) mode m

			                        return        power(a, m - 2, m);

			    }

			    // To compute x^y under modulo m
			// Iterative Java program to
			// compute modular power

			    static long power(long x, long y,long p)
			    {
			        // Initialize result
			        long res = 1;

			        // Update x if it is more
			        // than or equal to p
			        x = x % p;

			        while (y > 0)
			        {
			            // If y is odd, multiply x
			            // with result
			            if((y & 1)==1)
			                res = (res * x) % p;

			            // y must be even now
			            // y = y / 2
			            y = y >> 1;
			            x = (x * x) % p;
			        }
			        return res;
			    }
			static class Temp implements Comparable<Temp>{
				double a;
				int b;
				Temp(double a,int b){
					this.a = a;
					this.b = b;
				}
				@Override
				public int compareTo(Temp t){
					return Double.compare(this.a,t.a);
				}
			}
			static class Pair implements Comparable<Pair>{
				int first;
				int max;
				int second;
				int val1;
				int val2;
				boolean whole;

				Pair (int a,int b,int c,int val1,int val2,boolean whole){
					this.first = a;
					this.max = b;
					this.second = c;
					this.val1= val1;
					this.val2 = val2;
					this.whole = whole;
				}
				Pair(){

				}
				public boolean equals(Object o)
				{
					Pair p = (Pair)o;
					return (p.first==first && p.max==max) || (p.first == max && p.first == max);
				}
				public int hashCode()
				{
					return new Long(first).hashCode()*31 + new Long(max).hashCode();
				}
				public int compareTo(Pair p){
					return Long.compare(p.first,this.first);
				}
			}

		}


	import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.Stack;
import java.util.TreeSet;
		public class Main implements Runnable
		{
			static final long MOD = 1000000007L;
			static final long MOD2 = 1000000009L;
			static class InputReader
			{
				private InputStream stream;
				private byte[] buf = new byte[1024];
				private int curChar;
				private int numChars;
				private SpaceCharFilter filter;
				private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

				public InputReader(InputStream stream)
				{
					this.stream = stream;
				}

				public int read()
				{
					if (numChars==-1)
						throw new InputMismatchException();

					if (curChar >= numChars)
					{
						curChar = 0;
						try
						{
							numChars = stream.read(buf);
						}
						catch (IOException e)
						{
							throw new InputMismatchException();
						}

						if(numChars <= 0)
							return -1;
					}
					return buf[curChar++];
				}

				public String nextLine()
				{
					String str = "";
		            try
		            {
		                str = br.readLine();
		            }
		            catch (IOException e)
		            {
		                e.printStackTrace();
		            }
		            return str;
				}
				public int nextInt()
				{
					int c = read();

					while(isSpaceChar(c))
						c = read();

					int sgn = 1;

					if (c == '-')
					{
						sgn = -1;
						c = read();
					}

					int res = 0;
					do
					{
						if(c<'0'||c>'9')
							throw new InputMismatchException();
						res *= 10;
						res += c - '0';
						c = read();
					}
					while (!isSpaceChar(c));

					return res * sgn;
				}

				public long nextLong()
				{
					int c = read();
					while (isSpaceChar(c))
						c = read();
					int sgn = 1;
					if (c == '-')
					{
						sgn = -1;
						c = read();
					}
					long res = 0;

					do
					{
						if (c < '0' || c > '9')
							throw new InputMismatchException();
						res *= 10;
						res += c - '0';
						c = read();
					}
					while (!isSpaceChar(c));
						return res * sgn;
				}

				public double nextDouble()
				{
					int c = read();
					while (isSpaceChar(c))
						c = read();
					int sgn = 1;
					if (c == '-')
					{
						sgn = -1;
						c = read();
					}
					double res = 0;
					while (!isSpaceChar(c) && c != '.')
					{
						if (c == 'e' || c == 'E')
							return res * Math.pow(10, nextInt());
						if (c < '0' || c > '9')
							throw new InputMismatchException();
						res *= 10;
						res += c - '0';
						c = read();
					}
					if (c == '.')
					{
						c = read();
						double m = 1;
						while (!isSpaceChar(c))
						{
							if (c == 'e' || c == 'E')
								return res * Math.pow(10, nextInt());
							if (c < '0' || c > '9')
								throw new InputMismatchException();
							m /= 10;
							res += (c - '0') * m;
							c = read();
						}
					}
					return res * sgn;
				}

				public String readString()
				{
					int c = read();
					while (isSpaceChar(c))
						c = read();
					StringBuilder res = new StringBuilder();
					do
					{
						res.appendCodePoint(c);
						c = read();
					}
					while (!isSpaceChar(c));

					return res.toString();
				}

				public boolean isSpaceChar(int c)
				{
					if (filter != null)
						return filter.isSpaceChar(c);
					return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
				}

				public String next()
				{
					return readString();
				}

				public interface SpaceCharFilter
				{
					public boolean isSpaceChar(int ch);
				}
			}

			public static void main(String args[]) throws Exception
			{
				new Thread(null, new Main(),"Main",1<<26).start();
			}
			int MAXN = 1000001;
			public void run()
			{
				InputReader sc= new InputReader(System.in);
				PrintWriter w= new PrintWriter(System.out);
				String s = sc.next();
				Temp[] ans = new Temp[s.length()];
				double l = 0;
				double r = 1000001;
				for(int i = 0;i < s.length();i++) {
					double mid = (l + r)/2;
					if(s.charAt(i) == 'l') {
						r = mid;
					}else {
						l = mid;
					}
					ans[i] = new Temp(mid,i);
				}
				Arrays.sort(ans);
				long[] fans = new long[s.length()];
				for(int i = 0;i < ans.length;i++) {
					fans[i] = ans[i].b;
				}
				for(int i = 0;i < ans.length;i++) {
					w.println(fans[i]+1);
				}
				w.close();
			}

			static boolean isPrime(long n)
		    {
		        // Corner cases
		        if (n <= 1) return false;
		        if (n <= 3) return true;

		        // This is checked so that we can skip
		        // middle five numbers in below loop
		        if (n % 2 == 0 || n % 3 == 0) return false;

		        for (int i = 5; i * i <= n; i = i + 6)
		            if (n % i == 0 || n % (i + 2) == 0)
		            return false;

		        return true;
		    }

			long count = 0;
			long[][] dist;
			void flydwarShall(int k,int size) {
				for(int i = 0;i < size;i++) {
					for(int j = 0;j < size;j++) {
						if(dist[i][j] > dist[i][k] + dist[k][j]) {
							dist[i][j] = dist[i][k] + dist[k][j];
						}
					}
				}
			}
			Pair[] segTree;
			int[] arr;
			void build(int l,int r,int pos) {
				if(l == r) {
					segTree[pos] = new Pair(1,1,1,arr[l],arr[l],true);
					return;
				}
				int mid = (l + r) >> 1;
				build(l,mid,2*pos+1);
				build(mid+1, r, 2*pos+2);
				segTree[pos] = merge(segTree[2*pos+1], segTree[2*pos+2]);
			}
			Pair merge(Pair p1,Pair p2) {
				if(p1.val1 == 0) {
					return p2;
				}else if(p2.val1 == 0) {
					return p1;
				}
				Pair navi = new Pair();
				navi.val1 = p1.val1;
				navi.val2 = p2.val2;
				if(p1.val2 == p2.val1) {
					navi.max = Math.max(p1.max,p2.max);
					navi.first = p1.first;
					navi.second = p2.second;
					navi.whole = false;
				}else {
					navi.max = Math.max(p1.max,Math.max(p2.max,p1.second + p2.first));
					if(p1.whole && p2.whole) {
						navi.first = p1.first + p2.first;
						navi.second = p1.first + p2.first;
						navi.whole = true;
					}else if(p1.whole) {
						navi.first = p1.first + p2.first;
						navi.second = p2.second;
						navi.whole = false;
					}else if(p2.whole) {
						navi.first = p1.first;
						navi.second = p1.second + p2.first;
						navi.whole = false;
					}else {
						navi.first = p1.first;
						navi.second = p2.second;
						navi.whole = false;
					}
				}
				return navi;
			}
			Pair query(int pos, int l, int r, int start, int end)
			{
			    if(end < l || r < start)
			    {
			        return new Pair(0,0,0,0,0,false);
			    }
			    if(start <= l && r <= end)
			    {
			        // range represented by a node is completely inside the given range
			        return segTree[pos];
			    }
			    // range represented by a node is partially inside and partially outside the given range
			    int mid = (l + r) / 2;
			    Pair p1 = query(2*pos + 1, l, mid, start, end);
			    Pair p2 = query(2*pos+2, mid+1, r, start, end);
			    return merge(p1, p2);
			}
			int bsearch(Integer[] arr,int l,int r,int val) {
				int ind = -1;
				while(l <= r) {
					int mid = (l + r)/2;
					if(arr[mid] <= val) {
						l = mid + 1;
						ind = mid;
					}else {
						r = mid - 1;
					}
				}
				return ind;
			}
			Stack<Integer> st = new Stack();
			int bridges = 0;

			long modExpo(long a,long pow,long mod) {
				long res = 1;
				while(pow > 0) {
					if(pow % 2 == 1) {
						res = (res * a) % mod;
					}
					pow = pow/2;
					a = (a * a) % mod;
				}
				return res;
			}
			  static long modInverse(long a, long m)
			    {

			            // If a and m are relatively prime, then modulo inverse
			            // is a^(m-2) mode m

			                        return        power(a, m - 2, m);

			    }

			    // To compute x^y under modulo m
			// Iterative Java program to
			// compute modular power

			    static long power(long x, long y,long p)
			    {
			        // Initialize result
			        long res = 1;

			        // Update x if it is more
			        // than or equal to p
			        x = x % p;

			        while (y > 0)
			        {
			            // If y is odd, multiply x
			            // with result
			            if((y & 1)==1)
			                res = (res * x) % p;

			            // y must be even now
			            // y = y / 2
			            y = y >> 1;
			            x = (x * x) % p;
			        }
			        return res;
			    }
			static class Temp implements Comparable<Temp>{
				double a;
				int b;
				Temp(double a,int b){
					this.a = a;
					this.b = b;
				}
				@Override
				public int compareTo(Temp t){
					return Double.compare(this.a,t.a);
				}
			}
			static class Pair implements Comparable<Pair>{
				int first;
				int max;
				int second;
				int val1;
				int val2;
				boolean whole;

				Pair (int a,int b,int c,int val1,int val2,boolean whole){
					this.first = a;
					this.max = b;
					this.second = c;
					this.val1= val1;
					this.val2 = val2;
					this.whole = whole;
				}
				Pair(){

				}
				public boolean equals(Object o)
				{
					Pair p = (Pair)o;
					return (p.first==first && p.max==max) || (p.first == max && p.first == max);
				}
				public int hashCode()
				{
					return new Long(first).hashCode()*31 + new Long(max).hashCode();
				}
				public int compareTo(Pair p){
					return Long.compare(p.first,this.first);
				}
			}

		}


/*
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.
But if it had to perish twice,
I think I know enough of hate
To say that for destruction ice
Is also great
And would suffice.
*/
import java.io.*;
import java.util.*;

public final class Main{

    static class DSU{
        int[] parent;
        int[] size;
        DSU(int n){
            parent = new int[n + 1];
            size = new int[n + 1];
            for(int i = 0; i <= n; i++){
                parent[i] = i;
                size[i] = 1;
            }
        }
        int getRoot(int i){
            while(i != parent[i]){
                parent[i] = parent[parent[i]];
                i = parent[i];
            }
            return i;
        }
        boolean find(int i, int j){
            return (getRoot(i) == getRoot(j)) ? true : false;
        }
        void union(int i, int j){
            if(find(i, j))  return;
            int rooti = getRoot(i);
            int rootj = getRoot(j);
            if(size[rooti] > size[rootj]){
                parent[rootj] = rooti;
                size[rooti] += size[rootj];
            }
            else{
                parent[rooti] = rootj;
                size[rootj] += size[rooti];
            }
        }
    }

    public static final long MOD = 1000000007;
    public static final int limit = 1000005;

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        //int t = in.nextInt();
        int t=1;
        while (t-- > 0) {
            //w.println(n);
            String s = in.nextLine();
            int l = s.length();
            int[] ans = new int[l];
            int low = 0, high = l - 1;
            for(int i = 0; i < l; i++){
                if(s.charAt(i) == 'l'){
                    ans[high] = i + 1;
                    high--;
                }
                else{
                    ans[low] = i + 1;
                    low++;
                }
            }
            for(int i = 0; i < l; i++){
                System.out.println(ans[i]);
            }
        }
        w.close();
    }

    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

void solve()
{
   int n,i;
    cin>>n;
    vector<int>a(n),b(n);
    for(int &x:a)
        cin>>x;
    for(int &x:b)
        cin>>x;
   int  j=0,cnt=0;
    for(i=0;i<n;i++)
    {
        while(j<n)
        {
         if(a[i]==b[j])
         {
          cnt+=(j-i-cnt);
             break;
         }
         j++;
        }

    }
   cout<<cnt<<endl;
}

int main()
{
 ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    int t=1;
   // cin>>t;
    while(t--)
        solve();
}


#include<bits/stdc++.h>
#define f(i,j) for(int i=0;i<j;i++)
#define s(i) scanf("%d",&i)
#define ss(i) scanf("%s",i)
#define s2(i,j) scanf("%d %d",&i,&j)
#define s3(i,j,k) scanf("%d %d %d",&i,&j,&k)
#define ll long long int
using namespace std;

void func()
{
    return ;
}
int main()
{
   // freopen("input.txt","r",stdin);
    int n,enter[100001],exit[100001],pos=0,neg=0;
    bool ex[100001];
    s(n);
    f(i,n)
    {
        int x;
        s(x);
        enter[i+1]=x;
        ex[x]=false;
    }
     f(i,n)
    {
        int x;
        s(x);
        exit[i+1]=x;
    }

    int i=1,add=0,res=0,j=1;
    while(i<=n && j<=n)
    {
        while(ex[i]==true && i<n) i++;
        if(enter[i]==exit[j])
        {
            ex[exit[j]]=true;
            i++;
            j++;

        }
        else
        {
            while(enter[i]!=exit[j] && j<n)
            {
                ex[exit[j]]=true;
                j++;
                res++;
            }
            ex[exit[j]]=true;
            j++;
            i++;
        }

    }
    cout<<res<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define f(i,j) for(int i=0;i<j;i++)
#define s(i) scanf("%d",&i)
#define ss(i) scanf("%s",i)
#define s2(i,j) scanf("%d %d",&i,&j)
#define s3(i,j,k) scanf("%d %d %d",&i,&j,&k)
#define ll long long int
using namespace std;

void func()
{
    return ;
}
int main()
{
   // freopen("input.txt","r",stdin);
    int n,enter[100001],exit[100001],pos=0,neg=0;
    bool ex[100001];
    s(n);
    f(i,n)
    {
        int x;
        s(x);
        enter[i+1]=x;
        ex[x]=false;
    }
     f(i,n)
    {
        int x;
        s(x);
        exit[i+1]=x;
    }

    int i=1,add=0,res=0,j=1;
    while(i<=n && j<=n)
    {
        while(ex[i]==true && i<n) i++;
        if(enter[i]==exit[j])
        {
            ex[enter[i]]=true;
            i++;
            j++;

        }
        else
        {
            while(enter[i]!=exit[j] && j<n)
            {
                ex[exit[j]]=true;
                j++;
                res++;
            }
            ex[enter[i]]=true;
            j++;
            i++;
        }

    }
    cout<<res<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define f(i,j) for(int i=0;i<j;i++)
#define s(i) scanf("%d",&i)
#define ss(i) scanf("%s",i)
#define s2(i,j) scanf("%d %d",&i,&j)
#define s3(i,j,k) scanf("%d %d %d",&i,&j,&k)
#define ll long long int
using namespace std;

void func()
{
    return ;
}
int main()
{
    //freopen("input.txt","r",stdin);
    int n,enter[100001],exit[100001],pos=0,neg=0;
    s(n);
    f(i,n)
    {
        int x;
        s(x);
        enter[i+1]=x;
    }
     f(i,n)
    {
        int x;
        s(x);
        exit[x]=i+1;
    }

    int i=1,add=0,res=0,j=1;
    while(i<n && j<n)
    {
        if(exit[enter[i]]==j)
        {
            i++;
            j++;
        }
        else
        {
            while(exit[enter[i]]!=j)
            {
                j++;
                add++;
                res++;
            }
            j++;
            i++;
        }

    }
    cout<<res<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define f(i,j) for(int i=0;i<j;i++)
#define s(i) scanf("%d",&i)
#define ss(i) scanf("%s",i)
#define s2(i,j) scanf("%d %d",&i,&j)
#define s3(i,j,k) scanf("%d %d %d",&i,&j,&k)
#define ll long long int
using namespace std;

void func()
{
    return ;
}
int main()
{
   // freopen("input.txt","r",stdin);
    int n,enter[100001],exit[100001],pos=0,neg=0;
    bool ex[100001];
    s(n);
    f(i,n)
    {
        int x;
        s(x);
        enter[i+1]=x;
        ex[x]=false;
    }
     f(i,n)
    {
        int x;
        s(x);
        exit[i+1]=x;
    }

    int i=1,add=0,res=0,j=1;
    while(i<=n && j<=n)
    {
        while(ex[i]==true && i<n) i++;
        if(enter[i]==exit[j])
        {
            ex[enter[i]]=true;
            i++;
            j++;

        }
        else
        {
            while(enter[i]!=exit[j])
            {
                ex[j]=true;
                j++;
                add++;
                res++;
            }
            ex[enter[i]]=true;
            j++;
            i++;
        }

    }
    cout<<res<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define f(i,j) for(int i=0;i<j;i++)
#define s(i) scanf("%d",&i)
#define ss(i) scanf("%s",i)
#define s2(i,j) scanf("%d %d",&i,&j)
#define s3(i,j,k) scanf("%d %d %d",&i,&j,&k)
#define ll long long int
using namespace std;

void func()
{
    return ;
}
int main()
{
   // freopen("input.txt","r",stdin);
    int n,enter[100001],exit[100001],pos=0,neg=0;
    bool ex[100001];
    s(n);
    f(i,n)
    {
        int x;
        s(x);
        enter[i+1]=x;
        ex[x]=false;
    }
     f(i,n)
    {
        int x;
        s(x);
        exit[i+1]=x;
    }

    int i=1,add=0,res=0,j=1;
    while(i<=n && j<=n)
    {
        while(ex[i]==true && i<=n) i++;
        if(enter[i]==exit[j])
        {
            ex[enter[i]]=true;
            i++;
            j++;

        }
        else
        {
            while(enter[i]!=exit[j])
            {
                ex[j]=true;
                j++;
                add++;
                res++;
            }
            ex[enter[i]]=true;
            j++;
            i++;
        }

    }
    cout<<res<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define f(i,j) for(int i=0;i<j;i++)
#define s(i) scanf("%d",&i)
#define ss(i) scanf("%s",i)
#define s2(i,j) scanf("%d %d",&i,&j)
#define s3(i,j,k) scanf("%d %d %d",&i,&j,&k)
#define ll long long int
using namespace std;

void func()
{
    return ;
}
int main()
{
   // freopen("input.txt","r",stdin);
    int n,enter[100001],exit[100001],pos=0,neg=0;
    bool ex[100001];
    s(n);
    f(i,n)
    {
        int x;
        s(x);
        enter[i+1]=x;
        ex[x]=false;
    }
     f(i,n)
    {
        int x;
        s(x);
        exit[i+1]=x;
    }

    int i=1,add=0,res=0,j=1;
    while(i<=n && j<=n)
    {
        while(ex[enter[i]]==true && i<n) i++;
        if(enter[i]==exit[j])
        {
            ex[exit[j]]=true;
            i++;
            j++;

        }
        else
        {
            while(enter[i]!=exit[j] && j<n)
            {
                ex[exit[j]]=true;
                j++;
                res++;
            }
            ex[exit[j]]=true;
            j++;
            i++;
        }

    }
    cout<<res<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define f(i,j) for(int i=0;i<j;i++)
#define s(i) scanf("%d",&i)
#define ss(i) scanf("%s",i)
#define s2(i,j) scanf("%d %d",&i,&j)
#define s3(i,j,k) scanf("%d %d %d",&i,&j,&k)
#define ll long long int
using namespace std;

void func()
{
    return ;
}
int main()
{
    //freopen("input.txt","r",stdin);
    int n,enter[100001],exit[100001],pos=0,neg=0;
    s(n);
    f(i,n)
    {
        int x;
        s(x);
        enter[i+1]=x;
    }
     f(i,n)
    {
        int x;
        s(x);
        exit[x]=i+1;
    }

    int i=1,add=0,res=0,j=1;
    while(i<=n && j<=n)
    {
        if(exit[enter[i]]==j)
        {
            i++;
            j++;
        }
        else
        {
            while(exit[enter[i]]!=j)
            {
                j++;
                add++;
                res++;
            }
            j++;
            i++;
        }

    }
    cout<<res<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;

int main()
{
	ios :: sync_with_stdio(false) ;
	cin.tie(0) ;

	int n ;
	cin >> n ;

	vector<int> a(n), b(n) ;

	for(int i = 0 ; i < n ; i++)
	{
		cin >> a[i] ;
		--a[i] ;
	}

	for(int i = 0 ; i < n ; i++)
	{
		cin >> b[i] ;
		--b[i] ;
	}

	vector<int> pos(n) ;
	for(int i = 0 ; i < n ; i++)
		pos[b[i]] = i ;

	vector<int> c(n) ;
	for(int i = 0 ; i < n ; i++)
		c[i] = pos[a[i]] ;

	int mx = -1, ans = 0 ;
	for(int i = 0 ; i < n ; i++)
	{
		if(c[i] > mx)
			mx = c[i] ;
		else
			++ans ;
	}

	cout << ans << '\n' ;
	return 0 ;
}


#include<iostream>
using namespace std ;

int main()
{
	int n, arr[100000], tmp ;
	cin >> n ;
	for(int i = 0 ; i < n ; i++)
		cin >> arr[i] ;
	int j = 0, cnt = 0 ;
	for(int i = 0 ; i < n, i < n ; i++)
	{
		cin >> tmp ;
		if(!(arr[j] == tmp))
		{
			if(i != n-1)
				cnt++ ;
//			cout << tmp ;
		}
		else
			j++ ;
	}
//	while(k < n)
//		cin >> n ;
	cout << cnt << endl ;
}


#include<iostream>
using namespace std ;

int main()
{
	int n, arr[100000], tmp ;
	cin >> n ;
	for(int i = 0 ; i < n ; i++)
		cin >> arr[i] ;
	int j = 0, cnt = 0 ;
	for(int i = 0 ; i < n, j < n ; i++)
	{
		if(arr[j] == -1)
		{
			j++ ;
			continue ;
		}
		cin >> tmp ;
		if(!(arr[j] == tmp))
		{
			for(int k = j + 1 ; k < n ; k++)
				if(arr[k] == tmp)
				{
					arr[k] = -1 ;
					break ;
				}
			cnt++ ;

/*			cout << cnt << endl ;
			cout << "\n\nprint\n" ;
			for(int m = 0 ; m < n ; m++)
				cout << arr[m] << " " ;
			cout << "\n\n" ; */
		}
		else
			j++ ;
//		cout << "i = " << i << endl ;
	}
//	while(k < n)
//		cin >> n ;
	cout << cnt << endl ;
}


#include<iostream>
using namespace std ;

int main()
{
	ios :: sync_with_stdio(false) ;
	cin.tie(0) ;
	int n, arr[100000], tmp ;
	cin >> n ;
	for(int i = 0 ; i < n ; i++)
		cin >> arr[i] ;
	int j = 0, cnt = 0, pcnt = 0 ;
	for(int i = 0 ; i < n, j < n ; i++)
	{
		pcnt = 0 ;
		if(arr[j] == -1)
		{
			j++ ;
			continue ;
		}
		cin >> tmp ;
		if(!(arr[j] == tmp))
		{
			for(int k = j + 1 ; k < n ; k++)
				if(arr[k] == tmp)
				{
					arr[k] = -1 ;
					break ;
				}
			cnt++ ;
		}
		else
			j++ ;
	}
	cout << cnt << endl ;
}


#include<bits/stdc++.h>
using namespace std;
int a[100005],b[100005];
map<int,int> m;
map<int,int> p;
int main(){
    int n,sum=2000000;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        m[a[i]]=n+1-i;
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
        p[b[i]]=n+1-i+n;
    }
    for(int i=1;i<=n;i++){
        if(p[i]==0||m[i]==0) continue;
        sum=min(sum,p[i]-m[i]);
    }
    cout<<n-sum;
}


#include<bits/stdc++.h>
using namespace std;
int a[100005],b[100005];
map<int,int> m;
map<int,int> p;
int main(){
    int n,sum=2000000;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        m[a[i]]=n+1-i;
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
        p[b[i]]=n+1-i+n;
    }
    for(int i=1;i<=n;i++){
        sum=min(sum,p[i]-m[i]);
    }
    cout<<n-sum;
}


#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
set<int> t;
int main(){
    int n,a,b,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a;
        m[a]=i;
        t.insert(i);
    }
    for(int i=1;i<=n;i++){
        cin>>b;
        if(m[b]>*t.begin()) sum++;
        t.erase(m[b]);
    }
    cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
int a[100005],b[100005];
map<int,int> m;
map<int,int> p;
int main(){
    int n,sum=200000;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        m[a[i]]=n+1-i;
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
        p[b[i]]=n+1-i+n;
    }
    for(int i=1;i<=n;i++){
        sum=min(sum,p[i]-m[i]);
    }
    cout<<n-sum;
}


#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define maxn 100005
using namespace std;
int n, a[maxn], b[maxn], pos[maxn], f[maxn], res, cnt = 1, ans;
int main()
{
    ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
    ifstream cin("inp.txt");
#endif // ONLINE_JUDGE
    cin >> n;
    FOR(i, 1, n) cin >> a[i], pos[a[i]] = i;
    FOR(i, 1, n) cin >> b[i], f[i] = pos[b[i]];
    f[n+1] = 1e9;
    FOR(i, 1, n)
    if(f[i] > f[i+1]) ans += cnt, cnt = 0;
    else cnt++;
    cout << ans;

}


//Trương Minh Trí
#include <bits/stdc++.h>
#define FOR(i, x, y) for(int i = x; i <= y; ++i)
#define FORN(i, x, y) for(int i = x; i >= y; --i)
#define Task ""
#define maxn 100005
#define maxm
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
int n, a[maxn], b[maxn], q,ans;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
//    freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        int x;
        cin >> x;
        a[x] = i;
    }
    for(int i = 1;i <= n;i++)
    {
        int x;
        cin >> x;
        b[x] = i;
    }
    for(int i = 1;i <= n;i++)
    {
        ans = max(ans,b[i] - a[i]);
    }
    cout << ans;

}


#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define maxn 400005
using namespace std;
long long n, a[maxn], b[maxn], pos[maxn], f[maxn], fen[maxn], res;
void update(long long x){
    for(; x; x -= x & -x) fen[x]++;
}
long long get(long long x){
    long long ans = 0;
    for(; x <= n; x += x & -x) ans += fen[x];
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
    ifstream cin("inp.txt");
#endif // ONLINE_JUDGE
    cin >> n;
    FOR(i, 1, n) cin >> a[i], pos[a[i]] = i;
    FOR(i, 1, n) cin >> b[i], f[i] = pos[b[i]];
    FOR(i, 1, n){
        res = max(res, get(f[i] + 1));
        update(f[i]);
    }
    cout << res;

}


#include <bits/stdc++.h>
#define FOR(i, a, b) for(long long i = (a); i <= (b); i++)
#define FORR(i, a, b) for(long long i = (a); i >= (b); i--)
#define maxn 100005
using namespace std;
long long n, a[maxn], b[maxn], pos[maxn], f[maxn], fen[maxn], res;
void update(long long x){
    for(; x; x -= x & -x) fen[x]++;
}
long long get(long long x){
    long long ans = 0;
    for(; x <= n; x += x & -x) ans += fen[x];
    return ans;
}
long long main()
{
    ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
    ifstream cin("inp.txt");
#endif // ONLINE_JUDGE
    cin >> n;
    FOR(i, 1, n) cin >> a[i], pos[a[i]] = i;
    FOR(i, 1, n) cin >> b[i], f[i] = pos[b[i]];
    FOR(i, 1, n){
        res = max(res, get(f[i] + 1));
        update(f[i]);
    }
    cout << res;

}


#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define maxn 100005
using namespace std;
int n, a[maxn], b[maxn], pos[maxn], f[maxn], fen[maxn], res;
void update(int x){
    for(; x; x -= x & -x) fen[x]++;
}
int get(int x){
    int ans = 0;
    for(; x <= n; x += x & -x) ans += fen[x];
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
    ifstream cin("inp.txt");
#endif // ONLINE_JUDGE
    cin >> n;
    FOR(i, 1, n) cin >> a[i], pos[a[i]] = i;
    FOR(i, 1, n) cin >> b[i], f[i] = pos[b[i]];
    FOR(i, 1, n){
        res = max(res, get(f[i] + 1));
        update(f[i]);
    }
    cout << res;

}


#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define maxn 100005
using namespace std;
int n, a[maxn], b[maxn], pos[maxn], f[maxn], res, cnt, ans;
struct BIT{
    int fen[maxn];
    void update(int x){
    for(; x; x -= x & -x) fen[x]++;
    }
    int get(int x){
        int ans = 0;
        for(; x <= n; x += x & -x) ans += fen[x];
        return ans;
    }
}tree[1005];
int main()
{
    ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
    ifstream cin("inp.txt");
#endif // ONLINE_JUDGE
    cin >> n;
    FOR(i, 1, n) cin >> a[i], pos[a[i]] = i;
    FOR(i, 1, n) cin >> b[i], f[i] = pos[b[i]];
    FOR(i, 1, n){
        res = tree[cnt].get(f[i] + 1);
        if(res > 0) cnt++;
        ans += res;
        tree[cnt].update(f[i]);
    }
    cout << ans;

}


#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define maxn 100005
using namespace std;
int n, a[maxn], b[maxn], pos[maxn], f[maxn], res, cnt = 1, ans, r[maxn], maxr;
int main()
{
    ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
    ifstream cin("inp.txt");
#endif // ONLINE_JUDGE
    cin >> n;
    FOR(i, 1, n) cin >> a[i], pos[a[i]] = i;
    FOR(i, 1, n) cin >> b[i], f[i] = pos[b[i]], r[f[i]] = i;
    f[n+1] = 1e9;
    FOR(i, 1, n){
        if(r[i] - maxr - 1 > 0) ans += r[i] - maxr - 1;
        maxr = max(maxr, r[i]);
    }
    cout << ans;

}


#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define maxn 100005
using namespace std;
int n, a[maxn], b[maxn], pos[maxn], f[maxn], res, cnt = 1, ans;
int main()
{
    ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
    ifstream cin("inp.txt");
#endif // ONLINE_JUDGE
    cin >> n;
    FOR(i, 1, n) cin >> a[i], pos[a[i]] = i;
    FOR(i, 1, n) cin >> b[i], f[i] = pos[b[i]];
    f[n+1] = 1e9;
    FOR(i, 1, n)
    if(f[i] > f[i+1]) ans += cnt == 0 ? 1 : cnt, cnt = 0;
    else cnt++;
    cout << ans;

}


//IMPORTANT TWO POINTERS USE
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
typedef unsigned long long int ull;
typedef long long int ll;
typedef unsigned long int ul;
typedef long int l;
typedef long double ld;
using namespace std;
ll BS(vector<ll>& V,ll low,ll high,ll key);
void SieveOfEratosthenes(vector<ll>& V,ll num);
ll gcd(ll a,ll b);
ll lcm(ll a,ll b);
ull modularExponentiation(ull x,ull n,ull M);
int main()
{
    int N;
    cin>>N;
    vector<int>V;
    int B[N+1];
    int i,temp;
    for(i=0;i<N;i++)
    {
        cin>>temp;
        V.push_back(temp);
    }
    for(i=0;i<N;i++)
    {
        cin>>temp;
        B[temp]=i+1;
    }

    /*for(i=1;i<N+1;i++)
    {
        cout<<B[i]<<" ";
    }
    cout<<endl;*/

    i=1;
    int j=0;
    int cmp,cnt=0;
    while(i<N)
    {
       cmp=B[V[i]]-B[V[j]];
       if(cmp>0)// V[J] IS ON SAME SIDE(TO LEFT) OF V[I] IN BOTH PATTERNS
       {
           i++;
           j++;
           //WE INCREMENT BOTH SINCE IF V[I] OVERTAKED ANY ONE BEFORE (ALSO CONSIDERING V[J]) IT WILL ALWAYS HAVE HAD OVERTAKED V[J];
           //SO WE NEED TO CHECK ONLY JUST BEFORE ONE;
       }
       else
       {
           if(i==j+1);
          {
              i++;      //WE ONLY INCREMENTED I AND NOT J SINCE IN THE NEW PATTERN V[J] IS LAST ONE FOR NEXT V[I] AS THERE WAS AN ERROR SO INT CURRENT CASE V[J] WOULD
              j--;     //BE TO THE RIGHT RATHER THAN BEING ON LEFT IN NEW SEQUENCE;

          }
          j++;
           cnt++;
       }
    }

    cout<<cnt<<endl;
    return 0;
}
ll BS(vector<ll>& V,ll low,ll high,ll key)
{
    int mid=(low+high)/2;
    if(low<=high)
    {
        if(key==V[mid])
        {
            return mid;
        }
        else if(key<V[mid])
            {
               return BS(V,low,mid-1,key);
            }
            else
                return BS(V,mid+1,high,key);
    }
    return mid;//NOT -1 BUT MID SINCE WHEN YOU DON'T FIND A NUMBER USING BINARY SEARCH AT LAST IT IS POINTING TO NUMBER JUST SMALLER THAN OR
    //JUST GREATER THAN GIVEN NUMBER
}
void SieveOfEratosthenes(vector<ll>& V,ll num)
{

    bool prime[num+1];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=num; p++)
    {
        // IF prime[p] IS NOT CHANGED, THEN IT  IS  PRIME
        if (prime[p] == true)
        {

            for (ll i=p*p; i<=num; i += p)
                prime[i] = false;
        }
    }
    for(ll p=2; p<=num; p++)
       if (prime[p])
            V.push_back(p);//STORE ALL PRIME  NUMBERS

}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a, b);
}
ull modularExponentiation(ull x,ull n,ull M)
{
    ull result=1;
    while(n>0)
    {
        if(n % 2 ==1)
           result=(result * x)%M;
        x=(x*x)%M;
       n=n/2;
   }
    return result;
}


#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
typedef unsigned long long int ull;
typedef long long int ll;
typedef unsigned long int ul;
typedef long int l;
typedef long double ld;
using namespace std;
ll BS(vector<ll>& V,ll low,ll high,ll key);
void SieveOfEratosthenes(vector<ll>& V,ll num);
ll gcd(ll a,ll b);
ll lcm(ll a,ll b);
ull modularExponentiation(ull x,ull n,ull M);
int main()
{
    int N;
    cin>>N;
    vector<int>V;
    int B[N+1];
    int i,temp;
    for(i=0;i<N;i++)
    {
        cin>>temp;
        V.push_back(temp);
    }
    for(i=0;i<N;i++)
    {
        cin>>temp;
        B[temp]=i+1;
    }

    /*for(i=1;i<N+1;i++)
    {
        cout<<B[i]<<" ";
    }
    cout<<endl;*/

    i=1;
    int j=0;
    int cmp,cnt=0;
    while(i<N)
    {
        cmp=B[V[i]]-B[V[j]];
        if(cmp>0)
        {
            j++;
            if(j==i)
            {
                i++;
                j=0;
            }
        }
        else
        {
            cnt++;
            i=i+1;
            j=0;
        }
   }

    cout<<cnt<<endl;
    return 0;
}
ll BS(vector<ll>& V,ll low,ll high,ll key)
{
    int mid=(low+high)/2;
    if(low<=high)
    {
        if(key==V[mid])
        {
            return mid;
        }
        else if(key<V[mid])
            {
               return BS(V,low,mid-1,key);
            }
            else
                return BS(V,mid+1,high,key);
    }
    return mid;//NOT -1 BUT MID SINCE WHEN YOU DON'T FIND A NUMBER USING BINARY SEARCH AT LAST IT IS POINTING TO NUMBER JUST SMALLER THAN OR
    //JUST GREATER THAN GIVEN NUMBER
}
void SieveOfEratosthenes(vector<ll>& V,ll num)
{

    bool prime[num+1];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=num; p++)
    {
        // IF prime[p] IS NOT CHANGED, THEN IT  IS  PRIME
        if (prime[p] == true)
        {

            for (ll i=p*p; i<=num; i += p)
                prime[i] = false;
        }
    }
    for(ll p=2; p<=num; p++)
       if (prime[p])
            V.push_back(p);//STORE ALL PRIME  NUMBERS

}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a, b);
}
ull modularExponentiation(ull x,ull n,ull M)
{
    ull result=1;
    while(n>0)
    {
        if(n % 2 ==1)
           result=(result * x)%M;
        x=(x*x)%M;
       n=n/2;
   }
    return result;
}


//IMPORTANT TWO POINTERS USE
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
typedef unsigned long long int ull;
typedef long long int ll;
typedef unsigned long int ul;
typedef long int l;
typedef long double ld;
using namespace std;
ll BS(vector<ll>& V,ll low,ll high,ll key);
void SieveOfEratosthenes(vector<ll>& V,ll num);
ll gcd(ll a,ll b);
ll lcm(ll a,ll b);
ull modularExponentiation(ull x,ull n,ull M);
int main()
{
    int N;
    cin>>N;
    vector<int>V;
    int B[N+1];
    int i,temp;
    for(i=0;i<N;i++)
    {
        cin>>temp;
        V.push_back(temp);
    }
    for(i=0;i<N;i++)
    {
        cin>>temp;
        B[temp]=i+1;
    }

    /*for(i=1;i<N+1;i++)
    {
        cout<<B[i]<<" ";
    }
    cout<<endl;*/

    i=1;
    int j=0;
    int cmp,cnt=0;
    while(i<N)
    {
       cmp=B[V[i]]-B[V[j]];
       if(cmp>0)// V[J] IS ON SAME SIDE(TO LEFT) OF V[I] IN BOTH PATTERNS
       {
           i++;
           j=i-1;;
           //WE INCREMENT BOTH SINCE IF V[I] OVERTAKED ANY ONE BEFORE (ALSO CONSIDERING V[J]) IT WILL ALWAYS HAVE HAD OVERTAKED V[J];
           //SO WE NEED TO CHECK ONLY JUST BEFORE ONE;
       }
       else
       {
           if(i==j+1);
          {
              i++;      //WE ONLY INCREMENTED I AND NOT J SINCE IN THE NEW PATTERN V[J] IS LAST ONE FOR NEXT V[I] AS THERE WAS AN ERROR SO INT CURRENT CASE V[J] WOULD
              j--;     //BE TO THE RIGHT RATHER THAN BEING ON LEFT IN NEW SEQUENCE;

          }
          j++;
           cnt++;
       }
    }

    cout<<cnt<<endl;
    return 0;
}
ll BS(vector<ll>& V,ll low,ll high,ll key)
{
    int mid=(low+high)/2;
    if(low<=high)
    {
        if(key==V[mid])
        {
            return mid;
        }
        else if(key<V[mid])
            {
               return BS(V,low,mid-1,key);
            }
            else
                return BS(V,mid+1,high,key);
    }
    return mid;//NOT -1 BUT MID SINCE WHEN YOU DON'T FIND A NUMBER USING BINARY SEARCH AT LAST IT IS POINTING TO NUMBER JUST SMALLER THAN OR
    //JUST GREATER THAN GIVEN NUMBER
}
void SieveOfEratosthenes(vector<ll>& V,ll num)
{

    bool prime[num+1];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=num; p++)
    {
        // IF prime[p] IS NOT CHANGED, THEN IT  IS  PRIME
        if (prime[p] == true)
        {

            for (ll i=p*p; i<=num; i += p)
                prime[i] = false;
        }
    }
    for(ll p=2; p<=num; p++)
       if (prime[p])
            V.push_back(p);//STORE ALL PRIME  NUMBERS

}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a, b);
}
ull modularExponentiation(ull x,ull n,ull M)
{
    ull result=1;
    while(n>0)
    {
        if(n % 2 ==1)
           result=(result * x)%M;
        x=(x*x)%M;
       n=n/2;
   }
    return result;
}


//IMPORTANT TWO POINTERS USE
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
typedef unsigned long long int ull;
typedef long long int ll;
typedef unsigned long int ul;
typedef long int l;
typedef long double ld;
using namespace std;
ll BS(vector<ll>& V,ll low,ll high,ll key);
void SieveOfEratosthenes(vector<ll>& V,ll num);
ll gcd(ll a,ll b);
ll lcm(ll a,ll b);
ull modularExponentiation(ull x,ull n,ull M);
int main()
{
    int N;
    cin>>N;
    vector<int>V;
    int B[N+1];
    int i,temp;
    for(i=0;i<N;i++)
    {
        cin>>temp;
        V.push_back(temp);
    }
    for(i=0;i<N;i++)
    {
        cin>>temp;
        B[temp]=i+1;
    }

    /*for(i=1;i<N+1;i++)
    {
        cout<<B[i]<<" ";
    }
    cout<<endl;*/

    i=1;
    int j=0;
    int cmp,cnt=0;
    while(i<N)
    {
       cmp=B[V[i]]-B[V[j]];
       if(cmp>0)// V[J] IS ON SAME SIDE(TO LEFT) OF V[I] IN BOTH PATTERNS
       {
           i++;
           j++;
           //WE INCREMENT BOTH SINCE IF V[I] OVERTAKED ANY ONE BEFORE (ALSO CONSIDERING V[J]) IT WILL ALWAYS HAVE HAD OVERTAKED V[J];
           //SO WE NEED TO CHECK ONLY JUST BEFORE ONE;
       }
       else
       {
          i++;//WE ONLY INCREMENTED I AND NOT J SINCE IN THE NEW PATTERN V[J] IS LAST ONE FOR NEXT V[I] AS THERE WAS AN ERROR SO INT CURRENT CASE V[J] WOULD
            //BE TO THE RIGHT RATHER THAN BEING ON LEFT IN NEW SEQUENCE;
            cnt++;
       }
    }

    cout<<cnt<<endl;
    return 0;
}
ll BS(vector<ll>& V,ll low,ll high,ll key)
{
    int mid=(low+high)/2;
    if(low<=high)
    {
        if(key==V[mid])
        {
            return mid;
        }
        else if(key<V[mid])
            {
               return BS(V,low,mid-1,key);
            }
            else
                return BS(V,mid+1,high,key);
    }
    return mid;//NOT -1 BUT MID SINCE WHEN YOU DON'T FIND A NUMBER USING BINARY SEARCH AT LAST IT IS POINTING TO NUMBER JUST SMALLER THAN OR
    //JUST GREATER THAN GIVEN NUMBER
}
void SieveOfEratosthenes(vector<ll>& V,ll num)
{

    bool prime[num+1];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=num; p++)
    {
        // IF prime[p] IS NOT CHANGED, THEN IT  IS  PRIME
        if (prime[p] == true)
        {

            for (ll i=p*p; i<=num; i += p)
                prime[i] = false;
        }
    }
    for(ll p=2; p<=num; p++)
       if (prime[p])
            V.push_back(p);//STORE ALL PRIME  NUMBERS

}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a, b);
}
ull modularExponentiation(ull x,ull n,ull M)
{
    ull result=1;
    while(n>0)
    {
        if(n % 2 ==1)
           result=(result * x)%M;
        x=(x*x)%M;
       n=n/2;
   }
    return result;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    int a[n + 1], d[n + 1], vis[n + 1], val;
    for(int j = 1;j <= n;j++)
    {
        cin >> a[j];
    }
    for(int j = 1;j <= n;j++)
    {
        cin >> val;
        d[val] = j;
    }
    for(int j = 1;j <= n;j++)
        vis[j] = d[a[j]];
    int mx = vis[1], cnt = 0;
   /* for(int j = 1;j <= n;j++)
        cout << vis[j] << " ";
    cout << "\n";*/
    for(int j = 2;j <= n;j++)
    {
        if(vis[j] < mx)
        {
            cnt++;
        }
        mx = max(mx, vis[j]);
    }
    cout << cnt << "\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    int a[n + 1], c[n + 1], d[n + 1], vis[n + 1];
    for(int j = 1;j <= n;j++)
    {
        cin >> a[j];
        c[a[j]] = j;
    }
    for(int j = 1;j <= n;j++)
    {
        cin >> a[j];
        d[a[j]] = j;
    }
    int mx = 0;
    memset(vis, -1, sizeof(vis));
    for(int j = 1;j <= n;j++)
    {
        if(vis[j] == -1)
        {
            int x = c[j];
            int y = d[j];
            if(x > y)
                vis[j] = 0;
            else
            {
                while(x < y)
                {
                    vis[a[x]] = 1;
                    x++;
                }
            }
        }
    }
    for(int j = 1;j <= n;j++)
        if(vis[j] == 1)
            mx++;
    cout << mx << "\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    int a[n + 1], c[n + 1], d[n + 1];
    for(int j = 1;j <= n;j++)
    {
        cin >> a[j];
        c[a[j]] = j;
    }
    for(int j = 1;j <= n;j++)
    {
        cin >> a[j];
        d[a[j]] = j;
    }
    int mx = 0;
    for(int j = 1;j <= n;j++)
    {
        int x = c[j];
        int y = d[j];
        mx = max(mx, d[j] - c[j]);
    }
    cout << mx << "\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    int a[n + 1], c[n + 1], d[n + 1], vis[n + 1];
    for(int j = 1;j <= n;j++)
    {
        cin >> a[j];
        c[a[j]] = j;
    }
    for(int j = 1;j <= n;j++)
    {
        cin >> a[j];
        d[a[j]] = j;
    }
    int mx = 0;
    memset(vis, -1, sizeof(vis));
    for(int j = 1;j <= n;j++)
    {
        if(vis[j] == -1)
        {
            int x = c[j];
            int y = d[j];
            if(x > y)
                vis[j] = 1;
            else
            {
                while(x < y)
                {
                    vis[a[x]] = 1;
                    x++;
                }
            }
        }
    }
    for(int j = 1;j <= n;j++)
        if(vis[j] == 1)
            mx++;
    cout << mx << "\n";
    return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <string>
#include <deque>
#include <set>
#include <bitset>
#include <cstring>

//#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define p_b push_back
#define all(n) n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
#define mk_p make_pair
#define pr_setp(n)cout<<setprecision(2)<<n;
#define pr_setp1(n)cout<<setprecision(13)<<fixed<<n;
#define l_b lower_bound
#define u_b upper_bound
#define forall(it,v) for(auto it=v.begin();it!=v.end();it++)
#define forr(i,a,b) for(int i=(a);i<(b);i++)
#define forn(i,n) forr(i,0,n)
#define MAXP 131073
#define INF 10000000
#define Msize 100001
#define PI 3.1415926535897
#define MOD 1000000007LL
typedef long long ll;
const char sl='\n';
const int ssize =13847;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int n; cin >>n;
	set<int>nb;
	vector<int>a(n+1),b(n+1),c(n+1);
	vector<int>dp(n+1);
	for(int i = 1; i<=n;++i)
	{
		int x; cin >> x;
		a[x] = i;
	}
	int ans = 0;
	for(int i = 1; i<=n;++i)
	{
		int x; cin >> x;
		c[i] = x;
		b[a[x]] = i;
		auto tmp = nb.lower_bound(a[x]);
		if(tmp!=nb.end())
			dp[i] = 1+dp[b[*tmp]];
		nb.insert(a[x]);
		if(a[x]>i-dp[i])ans++;

	}
	cout<<ans<<sl;
	return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <string>
#include <deque>
#include <set>
#include <bitset>
#include <cstring>

//#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define p_b push_back
#define all(n) n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
#define mk_p make_pair
#define pr_setp(n)cout<<setprecision(2)<<n;
#define pr_setp1(n)cout<<setprecision(13)<<fixed<<n;
#define l_b lower_bound
#define u_b upper_bound
#define forall(it,v) for(auto it=v.begin();it!=v.end();it++)
#define forr(i,a,b) for(int i=(a);i<(b);i++)
#define forn(i,n) forr(i,0,n)
#define MAXP 131073
#define INF 10000000
#define Msize 100001
#define PI 3.1415926535897
#define MOD 1000000007LL
typedef long long ll;
const char sl='\n';
const int ssize =100005;
bitset<ssize>state;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int n; cin >> n;
	vector<int>a(n+1);
	state[0] = true;
	int j = 1;
	for(int i = 1; i<=n;++i)
	{
		int x; cin >> x;
		a[x] = i;
	}
	int ans = 0;
	for(int i= 1;i<=n;++i)
	{
		int x; cin >> x;
		if(j<a[x])ans++;
		state[a[x]] = true;
		while(state[j])j++;
	}
	cout<<ans<<sl;
	return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <string>
#include <deque>
#include <set>
#include <bitset>
#include <cstring>

//#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define p_b push_back
#define all(n) n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
#define mk_p make_pair
#define pr_setp(n)cout<<setprecision(2)<<n;
#define pr_setp1(n)cout<<setprecision(13)<<fixed<<n;
#define l_b lower_bound
#define u_b upper_bound
#define forall(it,v) for(auto it=v.begin();it!=v.end();it++)
#define forr(i,a,b) for(int i=(a);i<(b);i++)
#define forn(i,n) forr(i,0,n)
#define MAXP 131073
#define INF 10000000
#define Msize 100001
#define PI 3.1415926535897
#define MOD 1000000007LL
typedef long long ll;
const char sl='\n';
const int ssize =13847;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int n; cin >>n;
	set<int>nb;
	vector<int>a(n+1),b(n+1);//,c(n+1);
	vector<int>dp(n+1);
	for(int i = 1; i<=n;++i)
	{
		int x; cin >> x;
		a[x] = i;
	}
	int ans = 0;
	for(int i = 1; i<=n;++i)
	{
		int x; cin >> x;
		//c[i] = x;
		b[a[x]] = i;
		auto tmp = nb.lower_bound(a[x]);
		if(tmp!=nb.end())
			dp[i] = 1+dp[b[*tmp]];
		nb.insert(a[x]);
		if(a[x]!=i-dp[i])
		{
			//cout<<x<<"- "<<sl;
			ans++;
		}

	}
	cout<<ans<<sl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n];
	int b[n];
	vector<int>v(n,1);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	int i = 0;
	int j = 0;
	int count =0;
	while(i<n and j<n){
		if(a[i] == b[j]){
			i++,j++;
		}
		else if(v[i] == 0)i++;
		else {
			for(int k = j;k<n;k++){
				if(a[i] == b[k]){
					v[k] = 0;
					break;
				}
			}
			j++;
			count++;
		}
	}
	cout << count;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int a[n];
	int b[n];
	vector<int>v(n+1,1);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	int i = 0;
	int j = 0;
	int count =0;
	while(i<n and j<n){
		if(v[a[i]]==0)i++;
		else if(a[i] == b[j]){
			i++,j++;
		}
		else {
			v[b[j]] = 0;
			j++;
			count++;
		}
	}
	cout << count;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int a[n];
	int b[n];
	vector<int>v(n,1);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	int i = 0;
	int j = 0;
	int count =0;
	while(i<n and j<n){
		if(a[i] == b[j]){
			i++,j++;
		}
		else if(v[i] == 0)
			i++;
		else {
			for(int k = i;k<n;k++){
				if(a[k] == b[j]){
					v[k] = 0;
					break;
				}
			}
			j++;
			count++;
		}
	}
	cout << count;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n];
	int b[n];
	vector<int>v(n+1,1);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	int i = 0;
	int j = 0;
	int count =0;
	while(i<n and j<n){
		if(a[i] == b[j]){
			i++,j++;
		}
		else if(v[i] == 0)i++;
		else {
			v[b[j]]  = 0;
			j++;
			count++;
		}
	}
	cout << count;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n];
	int b[n];
	vector<int>v(n,1);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	int i = 0;
	int j = 0;
	int count =0;
	while(i<n and j<n){
		if(a[i] == b[j]){
			i++,j++;
		}
		else if(v[i] == 0)
			i++;
		else {
			for(int k = i;k<n;k++){
				if(a[k] == b[j]){
					v[k] = 0;
					break;
				}
			}
			j++;
			count++;
		}
	}
	cout << count;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int a[n];
	int b[n];
	vector<int>v(n+1,0);
	for(int i=0;i<n;i++){
		cin >> a[i];
		v[a[i]]++;
	}
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	int i = 0;
	int j = 0;
	int count =0;
	while(i<n and j<n){
		if(v[a[i]]==0)i++;
		else if(a[i] == b[j]){
			i++,j++;
		}
		else {
			if(v[b[j]>0])v[b[j]]--;
			j++;
			count++;
		}
	}
	cout << count;
}


#include <iostream>

using namespace std;

int poz[10001], v[10001], n, nrc;

int main()
{
    int i, j, x;

    cin >> n;

    for(i = 1; i <= n; ++i){
        cin >> v[i];
        poz[v[i]] = i;
    }

    for(i = 1; i <= n; ++i){
        cin >> x;

        if(poz[x] != i){
            ++nrc;

            for(j = poz[x]; j > i; --j){
                swap(v[j], v[j - 1]);
                ++poz[v[j]];
            }
        }
    }

    cout << nrc;

    return 0;
}


#include <iostream>

using namespace std;

int poz[100001], v[100001], v2[100001], deltapoz[100001], n, nrc;

int main()
{
    int i, j, x;

    cin >> n;

    for(i = 1; i <= n; ++i){
        cin >> v[i];
        poz[v[i]] = i;
    }

    for(i = 1; i <= n; ++i){
        cin >> v2[i];
    }

    for(i = 1; i <= n; ++i){
        if(poz[v2[i]] + deltapoz[v2[i]] != i){
            ++nrc;

            for(j = i - (poz[v2[i]] + deltapoz[v2[i]]); j < poz[v2[i]]; ++j)
                ++deltapoz[v[j]];
        }
    }

    cout << nrc;

    return 0;
}


#include <iostream>

using namespace std;

int v[100001], v2[100001], n, nrc;
bool mark[100001];

int main()
{
    int i, j, x;

    cin >> n;

    for(i = 1; i <= n; ++i){
        cin >> v[i];
    }

    for(i = 1; i <= n; ++i){
        cin >> v2[i];
    }

    for(i = j = 1; i <= n && j <= n; ++i){
        if(mark[v[i]] == 1)
            continue;
        if(v[i] != v2[j]){
            mark[v2[j]] = 1;
            ++nrc;
            ++j;
            --i;
            continue;
        }

        ++j;
    }

    cout << nrc;

    return 0;
}


#include <iostream>

using namespace std;

int poz[100001], v[100001], n, nrc;

int main()
{
    int i, j, x;

    cin >> n;

    for(i = 1; i <= n; ++i){
        cin >> v[i];
        poz[v[i]] = i;
    }

    for(i = 1; i <= n; ++i){
        cin >> x;

        if(poz[x] != i){
            ++nrc;

            for(j = poz[x]; j > i; --j){
                swap(v[j], v[j - 1]);
                ++poz[v[j]];
            }
        }
    }

    cout << nrc;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,f=0,l=1,r=0;
	cin>>n;
	long long int a[n],b[n],c[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[i]==b[j])
			{
				c[i]=j;
			}
		}
	}
	//for(int i=0;i<n;i++)
	{
	//	cout<<c[i]<<endl;
	}
	while(l<n)
	{
		while(r<n )
		{
			if(c[l]<c[r])
			{
				f++;
				break;
			}
			r++;
		}
		l++;
	}
	cout<<f;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,f=0,l=1,r=0,m;
	cin>>n;
	long long int a[n],b[n],c[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[i]==b[j])
			{
				c[i]=j;
			}
		}
	}
	//for(int i=0;i<n;i++)
	{
	//	cout<<c[i]<<endl;
	}
	m=c[0];
	for(int l=1;l<n;l++)
	{

		if(c[l]<m)
		{
			f++;
		}
		else
		{
			m=max(m,c[l]);
		}

	}
	cout<<f;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,f=0;
    cin >> n;
    int a[n], b[n], c[n];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        c[a[i]] = i;
    }
    for(int i = 0; i < n; i++)
    {
        cin >> b[i];
        b[i] = c[b[i]];
    }
    int m = 1e5 + 5;
    for(int i = n-1; i >= 0; i--)
    {
        m = min(m, b[i]);
        if(b[i] > m)
            f++;
    }
    cout << f;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,f=0;
    cin >> n;
    int a[n], b[n], c[n];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        c[a[i]] = i;
    }
    for(int i = 0; i < n; i++)
    {
        cin >> b[i];
        b[i] = c[b[i]];
    }
    int m = 1e5 + 5, ;
    for(int i = n-1; i >= 0; i--)
    {
        m = min(m, b[i]);
        if(b[i] > m)
            f++;
    }
    cout << f;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,f=0,l=1,r=0;
	cin>>n;
	long long int a[n],b[n],c[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[i]==b[j])
			{
				c[i]=j;
			}
		}
	}
	//for(int i=0;i<n;i++)
	{
	//	cout<<c[i]<<endl;
	}
	while(l<n)
	{
		r=0;
		while(r<l )
		{
			if(c[l]<c[r])
			{
				f++;
				break;
			}
			r++;
		}
		l++;
	}
	cout<<f;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,f=0,l=1,r=0,m;
	cin>>n;
	long long int a[n],b[n],c[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[i]==b[j])
			{
				c[i]=j;
			}
		}
	}
	//for(int i=0;i<n;i++)
	{
	//	cout<<c[i]<<endl;
	}
	m=c[0];
	while(l<n)
	{

		if(c[l]<m)
		{
			f++;
		}
		else
		{
			m=c[l];
		}

		l++;
	}
	cout<<f;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,f=0,l=1,r=0,m;
	cin>>n;
	long long int a[n],b[n],c[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[i]==b[j])
			{
				c[i]=j;
			}
		}
	}
	//for(int i=0;i<n;i++)
	{
	//	cout<<c[i]<<endl;
	}
	m=c[0];
	while(l<n)
	{

		if(c[l]<m)
		{
			f++;
		}
		else
		{
			m=max(m,c[l]);
		}

		l++;
	}
	cout<<f;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,maax = -1, result = 0;
    cin >> n;

    vector<int> in(n),out(n);

    for(int i = 0; i < n; i++) {
        cin >> in[i];
        in[i]--;
    }

    for(int i = 0; i < n; i++) {
        cin >> out[i];
        out[i]--;
        }

     map<int,int> pos;
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    pos[out[i]] = i;
    c[i] = pos[in[i]];
  }

 /* for (int i = 0; i < n; i++) {
    c[i] = pos[a[i]];
  }*/

    for(int i = 0; i < n; i++) {
        if(c[i] < maax)
            result++;
        else
            maax = c[i];
    }
    cout <<result << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,maax = -1, result = 0;
    cin >> n;

    vector<int> in(n),out(n);

    for(int i = 0; i < n; i++) {
        cin >> in[i];
        in[i]--;
    }

    for(int i = 0; i < n; i++) {
        cin >> out[i];
        out[i]--;
        }

     map<int,int> pos;
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    pos[out[i]] = i;
    c[i] = pos.find(in[i])->second;
  }

 /* for (int i = 0; i < n; i++) {
    c[i] = pos[a[i]];
  }*/

    for(int i = 0; i < n; i++) {
        if(c[i] < maax)
            result++;
        else
            maax = c[i];
    }
    cout <<result;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    --a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    --b[i];
  }
  vector<int> pos(n);
  for (int i = 0; i < n; i++) {
    pos[b[i]] = i;
  }
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    c[i] = pos[a[i]];
  }
  int mx = -1, ans = 0;
  for (int i = 0; i < n; i++) {
    if (c[i] > mx) {
      mx = c[i];
    } else {
      ++ans;
    }
  }
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,maax = -1, result = 0;
    cin >> n;

    vector<int> in(n),out(n);

    for(int i = 0; i < n; i++) {
        cin >> in[i];
        in[i]--;
    }

    for(int i = 0; i < n; i++) {
        cin >> out[i];
        out[i]--;
        }

     map<int,int> pos;
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    pos[out[i]] = i;
  }
  for(int i = 0; i < n; i++) {
    c[i] = pos.find(in[i])->second;
  }

 /* for (int i = 0; i < n; i++) {
    c[i] = pos[a[i]];
  }*/

    for(int i = 0; i < n; i++) {
        if(c[i] < maax)
            result++;
        else
            maax = c[i];
    }
    cout <<result;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,maax = -1, result = 0;
    cin >> n;

    vector<int> in(n),out(n);

    for(int i = 0; i < n; i++) {
        cin >> in[i];
        in[i]--;
    }

    for(int i = 0; i < n; i++) {
        cin >> out[i];
        out[i]--;
        }

     vector<int> pos(n);
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    pos[out[i]] = i;
    c[i] = pos[in[i]];
  }
    for(int i = 0; i < n; i++) {
        if(c[i] < maax)
            result++;
        else
            maax = c[i];
    }
    cout <<result << endl;
    return 0;
}


#include<bits/stdc++.h>
#define bi (1<<i)
#define bk (1<<k)
#define bj (1<<j)
#define ls (rt<<1)
#define rs (rt<<1|1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long ll;
const ll N=3e5+2;
ll a[N],b[N],v[N],d[N];
int main()
{
   // freopen("i.txt","r",stdin);
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
        d[a[i]]=i;
    }
    for(int i=0; i<n; i++)
        scanf("%lld",&b[i]);
    int ans=0,p=0;
    for(int i=0; i<n; i++)
    {
        if(v[a[i]])p--;
        if(d[b[i]]+p>i)
        {
           // cout<<b[i]<<endl;
            ans++,p++;
        }
        v[b[i]]++;
    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
#define bi (1<<i)
#define bk (1<<k)
#define bj (1<<j)
#define ls (rt<<1)
#define rs (rt<<1|1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long ll;
const ll N=3e5+2;
ll a[N],b[N],vis[N],d[N];
int main()
{
    //freopen("i.txt","r",stdin);
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
    }
    for(int i=0; i<n; i++)
    {
        scanf("%lld",&b[i]);
        d[b[i]]=i;
    }
    int as=0;
    for(int i=0; i<n; i++)
    {
        int j=d[a[i]],cnt=-1;
       // cout<<j<<' ';
        while(j>=0&&!vis[j])vis[j--]++,cnt++;
      //  cout<<j<<' '<<cnt<<endl;
        as+=max(cnt,0);
    }
    printf("%d\n",as);
}


#include<bits/stdc++.h>
#define bi (1<<i)
#define bk (1<<k)
#define bj (1<<j)
#define ls (rt<<1)
#define rs (rt<<1|1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long ll;
const ll N=3e5+2;
ll a[N],b[N],v[N],d[N];
int main()
{
  //  freopen("i.txt","r",stdin);
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
        d[a[i]]=n-i-1;
    }
    for(int i=0; i<n; i++)
        scanf("%lld",&b[i]);
    int ans=0,p=0;
    for(int i=0; i<n; i++)
    {

        if(d[b[i]]<n-i-1+p)
        {
            v[b[i]]++;
            ans++,p++;
            //cout<<b[i]<<endl;
        }
        if(v[a[i]])p--;

    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
#define bi (1<<i)
#define bk (1<<k)
#define bj (1<<j)
#define ls (rt<<1)
#define rs (rt<<1|1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long ll;
const ll N=3e5+2;
ll a[N],b[N],v[N],d[N];
int main()
{
  //  freopen("i.txt","r",stdin);
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
        d[a[i]]=n-i-1;
    }
    for(int i=0; i<n; i++)
        scanf("%lld",&b[i]);
    int ans=0,p=0;
    for(int i=0; i<n; i++)
    {
        if(v[a[i]])p--;
        if(d[b[i]]<n-i-1+p)
        {
            v[b[i]]++;
            ans++,p++;
            //cout<<b[i]<<endl;
        }

    }
    printf("%d\n",ans);
}


#include "bits/stdc++.h"

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    vector<int> mapping(n);
    map<int, bool> enters;

    for (int i = 0; i < n; ++i) {
        enter[i] = true;
        int t;
        cin >> t;
        mapping[t] = i;
    }

    vector<int> exits(n);
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        exits[i] = mapping[t];
    }

    int overtake = 0;
    for (int i = 0; i < n; ++i) {
        if (enters.begin()->first == exits[i]) {
            enters.erase(enters.begin());
        } else {
            overtake++;
            enters.erase(exits[i]);
        }
    }

    cout << overtake << endl;

    return 0;
}


#include "bits/stdc++.h"

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    vector<int> mapping(n);
    map<int, bool> enter;

    for (int i = 0; i < n; ++i) {
        enter[i] = true;
        int t;
        cin >> t;
        mapping[t] = i;
    }

    vector<int> exit(n);
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        exit[i] = mapping[t];
    }

    int overtake = 0;
    for (int i = 0; i < n; ++i) {
        if (enter.begin()->first == exit[i]) {
            enter.erase(enter.begin());
        } else {
            overtake++;
            enter.erase(exit[i]);
        }
    }

    cout << overtake << endl;
    return 0;
}


#include "bits/stdc++.h"

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    vector<int> mapping(n + 5);
    map<int, bool> enters;

    for (int i = 0; i < n; ++i) {
        enters[i] = true;
        int t;
        cin >> t;
        mapping[t] = i;
    }

    vector<int> exits(n + 5);
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        exits[i] = mapping[t];
    }

    int overtake = 0;
    for (int i = 0; i < n; ++i) {
        if (enters.begin()->first == exits[i]) {
            enters.erase(enters.begin());
        } else {
            overtake++;
            enters.erase(exits[i]);
        }
    }

    cout << overtake << endl;

    return 0;
}


#include "bits/stdc++.h"

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    vector<int> mapping(n);
    map<int, bool> enters;

    for (int i = 0; i < n; ++i) {
        enters[i] = true;
        int t;
        cin >> t;
        mapping[t] = i;
    }

    vector<int> exits(n);
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        exits[i] = mapping[t];
    }

    int overtake = 0;
    for (int i = 0; i < n; ++i) {
        if (enters.begin()->first == exits[i]) {
            enters.erase(enters.begin());
        } else {
            overtake++;
            enters.erase(exits[i]);
        }
    }

    cout << overtake << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[100005],b[100005];
int en[100005],ou[100005];
int n,dis;
long long ans;
int main()
{

	cin>>n;
	for(int i=1;i<=n;i++)
	{
	cin>>a[i];
	en[a[i]]=i;
	}
	for(int i=1;i<n;i++)
	{
	cin>>b[i];
	ou[b[i]]=i;
	}
	int i,j;
	i=1;j=1;
	while(i<=n&&j<=n)
	{
		if(a[i]==b[j])
		{
			i++;
			j++;
			ans++;
		}
		else
		{
			while(b[j]!=a[i])j++;
			i++;
			j++;
			ans++;
			continue;
		}
	}
	cout<<n-ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[100005],b[100005];
int vis[100005];
int n,dis;
long long ans;
int main()
{

	cin>>n;
	for(int i=1;i<=n;i++)
	{
	cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
	cin>>b[i];
	}
	int i,j;
	i=1;j=1;
	while(i<=n&&j<=n)
	{
		if(vis[a[i]]==1)
		{
			i++;
			continue;
		}
		if(a[i]==b[j])
		{
			//cout<<a[i]<<endl;
			i++;
			j++;
			ans++;
		}
		else
		{
			while(j<=n&&b[j]!=a[i])
			{
				vis[b[j]]=1;
				j++;
			}
			if(j>n)break;
			//cout<<a[i]<<endl;
			i++;
			j++;
			ans++;

			continue;
		}
	}
	cout<<n-ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[100005],b[100005];
int en[100005],ou[100005];
int n,dis;
long long ans;
int main()
{

	cin>>n;
	for(int i=1;i<=n;i++)
	{
	cin>>a[i];
	en[a[i]]=i;
	}
	for(int i=1;i<n;i++)
	{
	cin>>b[i];
	ou[b[i]]=i;
	}
	int i,j;
	i=1;j=1;
	while(i<=n&&j<=n)
	{
		if(a[i]==b[j])
		{
			i++;
			j++;
			ans++;
			continue;
		}
		else
		{
			while(j<=n&&b[j]!=a[i])j++;
			if(j>n)break;
			i++;
			j++;
			ans++;
			continue;
		}
	}
	cout<<n-ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[100005],b[100005];
int en[100005],ou[100005];
int n,dis;
long long ans;
int main()
{

	cin>>n;
	for(int i=1;i<=n;i++)
	{
	cin>>a[i];
	en[a[i]]=i;
	}
	for(int i=1;i<n;i++)
	{
	cin>>b[i];
	ou[b[i]]=i;
	}
	int i,j;
	i=1;j=1;
	while(i<=n&&j<=n)
	{
		if(a[i]==b[j])
		{
			i++;
			j++;
			ans++;
		}
		else
		{
			while(j<=n&&b[j]!=a[i])j++;
			i++;
			j++;
			ans++;
			continue;
		}
	}
	cout<<n-ans;
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <map>
#include <cmath>
#include <queue>
#define ll long long
#define pii pair<int ,int >
using namespace std;
void swap(int &x,int &y){int t=x;x=y;y=t;}
const int maxm=1000005;
const int maxn=100005;
const int inf=0x7fffffff;
int n,k;
int t[maxn],s[maxn],vis[maxn];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&t[i]);
    for(int i=0;i<n;i++)scanf("%d",&s[i]);
    int a=0,b=0,sum=0;
    for(int i=0;i<n;i++){
        if(a>=n)break;
        while(vis[t[a]]){
            a++;
        }
        if(a>=n)break;
        if(t[a]==s[i]){
            a++;
            vis[s[i]]=1;
        }else{
            sum++;
            vis[s[i]]=1;
            cout<<s[i]<<endl;
        }
    }
    printf("%d",sum);
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <map>
#include <cmath>
#include <queue>
#define ll long long
#define pii pair<int ,int >
using namespace std;
void swap(int &x,int &y){int t=x;x=y;y=t;}
const int maxm=1000005;
const int maxn=100005;
const int inf=0x7fffffff;
int n,k;
int t[maxn],s[maxn],vis[maxn];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&t[i]);
    for(int i=0;i<n;i++)scanf("%d",&s[i]);
    int a=0,b=0,sum=0;
    for(int i=0;i<n;i++){
        if(vis[t[a]]){
            a++;
            continue;
        }
        if(a>=n||b>=n)break;
        if(t[a]==s[b]){
            a++;b++;
            vis[b]=1;
        }else{
            sum++;
            vis[s[b++]]=1;
        }
    }
    printf("%d",sum);
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <map>
#include <cmath>
#include <queue>
#define ll long long
#define pii pair<int ,int >
using namespace std;
void swap(int &x,int &y){int t=x;x=y;y=t;}
const int maxm=1000005;
const int maxn=100005;
const int inf=0x7fffffff;
int n,k;
int t[maxn],s[maxn],vis[maxn];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&t[i]);
    for(int i=0;i<n;i++)scanf("%d",&s[i]);
    int a=0,b=0,sum=0;
    for(int i=0;i<n;i++){
        if(a>=n)break;
        while(vis[t[a]]){
            a++;
        }
        if(a>=n)break;
        if(t[a]==s[i]){
            a++;
            vis[s[i]]=1;
        }else{
            sum++;
            vis[s[i]]=1;
            //cout<<s[i]<<endl;
        }
    }
    printf("%d",sum);
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <map>
#include <cmath>
#include <queue>
#define ll long long
#define pii pair<int ,int >
using namespace std;
void swap(int &x,int &y){int t=x;x=y;y=t;}
const int maxm=1000005;
const int maxn=100005;
const int inf=0x7fffffff;
int n,k;
int t[maxn],s[maxn],vis[maxn];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&t[i]);
    for(int i=0;i<n;i++)scanf("%d",&s[i]);
    int a=0,b=0,sum=0;
    for(int i=0;i<n;i++){
        if(vis[t[a]]){
            a++;
            continue;
        }
        if(t[a]==s[b]){
            a++;b++;
            vis[b]=1;
        }else{
            sum++;
            vis[s[b++]]=1;
        }
    }
    printf("%d",sum);
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <map>
#include <cmath>
#include <queue>
#define ll long long
#define pii pair<int ,int >
using namespace std;
void swap(int &x,int &y){int t=x;x=y;y=t;}
const int maxm=1000005;
const int maxn=100005;
const int inf=0x7fffffff;
int n,k;
int t[maxn],s[maxn],vis[maxn];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&t[i]);
    for(int i=0;i<n;i++)scanf("%d",&s[i]);
    int a=0,b=0,sum=0;
    for(int i=0;i<n;i++){
        if(vis[t[a]]){
            a++;
            continue;
        }
        if(a==n||b==n)break;
        if(t[a]==s[b]){
            a++;b++;
            vis[b]=1;
        }else{
            sum++;
            vis[s[b++]]=1;
        }
    }
    printf("%d",sum);
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <map>
#include <cmath>
#include <queue>
#define ll long long
#define pii pair<int ,int >
using namespace std;
void swap(int &x,int &y){int t=x;x=y;y=t;}
const int maxm=1000005;
const int maxn=100005;
const int inf=0x7fffffff;
int n,k;
int t[maxn],s[maxn],vis[maxn];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&t[i]);
    for(int i=0;i<n;i++)scanf("%d",&s[i]);
    int a=0,b=0,sum=0;
    for(int i=0;i<n;i++){
        if(vis[t[a]]){
            a++;
            continue;
        }
        if(a>=n)break;
        if(t[a]==s[i]){
            a++;
            vis[s[i]]=1;
        }else{
            sum++;
            vis[s[i]]=1;
        }
    }
    printf("%d",sum);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[100005];
int b[100005];
bool c[100005];
int main()
{
	int n;
	cin >> n;
	memset(c, false, sizeof(c));
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	for (int i = 0;i < n;i++) {
		cin >> b[i];
	}
	int count = 0;
	int j=0, k=0;
	while (1) {
		if (j == n) {
			break;
		}
		if (c[a[j]]) {
			j++;
			continue;
		}
		if (a[j] == b[k]) {
			c[b[k]] = true;
			j++;
			k++;
		}
		else {
			count++;
			c[b[k]] = true;
			k++;
		}
	}
	printf("%d\n", count);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[100005];
int b[100005];
bool c[100005];
int main()
{
	int n;
	cin >> n;
	memset(c, false, sizeof(c));
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	for (int i = 0;i < n;i++) {
		cin >> b[i];
	}
	int count = 0;
	int j=0, k=0;
	while (1) {
		if (k == n) {
			break;
		}
		if (c[j]) {
			j++;
		}
		if (a[j] == b[k]) {
			j++;
			k++;
			c[b[k]] = true;
		}
		else {
			count++;
			c[b[k]] = true;
			k++;
		}
	}
	printf("%d\n", count);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[100005];
int b[100005];
bool c[100005];
int main()
{
	int n;
	cin >> n;
	memset(c, false, sizeof(c));
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	for (int i = 0;i < n;i++) {
		cin >> b[i];
	}
	int count = 0;
	int j=0, k=0;
	while (1) {
		if (j == n) {
			break;
		}
		if (c[a[j]]) {
			j++;
		}
		if (a[j] == b[k]) {
			c[b[k]] = true;
			j++;
			k++;
		}
		else {
			count++;
			c[b[k]] = true;
			k++;
		}
	}
	printf("%d\n", count);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[100005];
int b[100005];
bool c[100005];
int main()
{
	int n;
	cin >> n;
	memset(c, false, sizeof(c));
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	for (int i = 0;i < n;i++) {
		cin >> b[i];
	}
	int count = 0;
	int j=0, k=0;
	while (1) {
		if (k == n) {
			break;
		}
		if (c[a[j]]) {
			j++;
		}
		if (a[j] == b[k]) {
			j++;
			k++;
			c[b[k]] = true;
		}
		else {
			count++;
			c[b[k]] = true;
			k++;
		}
	}
	printf("%d\n", count);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[100005];
int b[100005];
bool c[100005];
int main()
{
	int n;
	cin >> n;
	memset(c, false, sizeof(c));
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	for (int i = 0;i < n;i++) {
		cin >> b[i];
	}
	int count = 0;
	int j=0, k=0;
	while (1) {
		if (k == n) {
			break;
		}
		if (c[a[j]]) {
			j++;
		}
		if (a[j] == b[k]) {
			c[b[k]] = true;
			j++;
			k++;
		}
		else {
			count++;
			c[b[k]] = true;
			k++;
		}
	}
	printf("%d\n", count);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[100005];
int b[100005];
bool c[100005];
int main()
{
	int n;
	cin >> n;
	memset(c, false, sizeof(c));
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	for (int i = 0;i < n;i++) {
		cin >> b[i];
	}
	int count = 0;
	int j=0, k=0;
	while (1) {
		if (k == n) {
			break;
		}
		if (c[j]) {
			j++;
		}
		if (a[j] == b[k]) {
			j++;
			k++;
		}
		else {
			count++;
			c[b[k]] = true;
			k++;
		}
	}
	printf("%d\n", count);
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
#include <string.h>
#include <bits/stdc++.h>
#define LL long long int
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define debug(x) cout << #x << " :: " << x << endl;
#define debug2(x, y) cout << #x << " :: " << x << "\t" << #y << " :: " << y << endl;
#define debug3(x, y, z) cout << #x << " :: " << x << "\t" << #y << " :: " << y << "\t" << #z << " :: " << z << endl;
#define mem(x, val) memset(x, val, sizeof(x))
#define setbits(x) __builtin_popcount(x)
#define all(c) (c).begin(), (c).end()
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef pair<int, int> PI;
typedef pair<LL, LL> PL;
typedef vector<PI> VPI;
typedef vector<PL> VPL;
LL mod = 1000000007;
inline void fastio()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
LL pow(LL n, LL m)
{
    if (m == 0)
        return 1;
    else if (m == 1)
        return n;
    LL ans = pow(n, m / 2) % mod;
    if (m % 2 == 1)
        return (((ans * ans) % mod) * n) % mod;
    else
        return (ans * ans) % mod;
}
int main()
{
    fastio();
    int n,i,j,k,a[100005],b[100005],t=0;;
    map<int,int> m;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>j;
        a[i]=j;
        m[j]=i;
    }
    int v[100005];
    for(i=1;i<=n;i++)
    {
        cin>>j;
        k=m[j];
        v[i]+=v[i-1];

        if(i<m[j]+v[i])
        {
            t++;
            v[i]++;
            v[k+1]--;
        }
    }
    cout<<t;

    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
#include <string.h>
#include <bits/stdc++.h>
#define LL long long int
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define debug(x) cout << #x << " :: " << x << endl;
#define debug2(x, y) cout << #x << " :: " << x << "\t" << #y << " :: " << y << endl;
#define debug3(x, y, z) cout << #x << " :: " << x << "\t" << #y << " :: " << y << "\t" << #z << " :: " << z << endl;
#define mem(x, val) memset(x, val, sizeof(x))
#define setbits(x) __builtin_popcount(x)
#define all(c) (c).begin(), (c).end()
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef pair<int, int> PI;
typedef pair<LL, LL> PL;
typedef vector<PI> VPI;
typedef vector<PL> VPL;
LL mod = 1000000007;
inline void fastio()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
LL pow(LL n, LL m)
{
    if (m == 0)
        return 1;
    else if (m == 1)
        return n;
    LL ans = pow(n, m / 2) % mod;
    if (m % 2 == 1)
        return (((ans * ans) % mod) * n) % mod;
    else
        return (ans * ans) % mod;
}
int main()
{
    fastio();
    int n,i,j,k,a[100005],b[100005],t=0;;
    map<int,int> m;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>j;
        a[i]=j;
        m[j]=i;
    }
    int v[100005]={0};
    for(i=1;i<=n;i++)
    {
        cin>>j;
        k=m[j];
        v[i]+=v[i-1];
        if(i<k+v[i])
        {
            t++;
            v[i]++;
            v[k+1]--;
        }
    }
    cout<<t;

    return 0;
}