// Arup Guha
// 3/4/2022
// Solution to 2022 February Bronze USACO Problem: Photoshoot 2

import java.util.*;

public class photoshoot {

	public static int n;
	public static int[] arr1;
	public static int[] arr2;
	public static int[] map;
	
	public static void main(String[] args) {
	
		// Set up arrays.
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		arr1 = new int[n];
		arr2 = new int[n];
		map = new int[n];
		
		// Read in first array.
		for (int i=0; i<n; i++) {
			arr1[i] = stdin.nextInt()-1;
			map[arr1[i]] = i;
		}
		// Read in second array and store its inverse.
		for (int i=0; i<n; i++) {
			arr2[i] = stdin.nextInt()-1;
		}
		
		int next = 0, res = 0;
		
		for (int i=0; i<n; i++) {
			
			// Find where in list 1, this next item from list 2 is.
			int idx = map[arr2[i]];
			
			if (idx > next) 
				res++;
			
			// Now, I don't count.
			arr1[idx] = -1;
			
			// Advance to next unused spot.
			while (next < n && arr1[next] == -1) next++;
		}
		
		System.out.println(res);
	}
	
	
}