import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } int[] order = new int[n + 1]; for (int i = 0; i < n; i++) { order[sc.nextInt()] = i; } int count = 0; for (int i = n - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (order[arr[j]] > order[arr[j + 1]]) { int tmp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = tmp; count++; } } } System.out.println(count); } }