import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N = int(input()) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] dic = {} for i, b in enumerate(B): dic[b] = i C = [] for a in A: C.append(dic[a]) def babble_sort(arr): N = len(arr) x = 0 for i in range(N - 1): cnt = 0 for j in range(0, N - 1 - i): if arr[j] > arr[j + 1]: arr[j], arr[j + 1] = arr[j + 1], arr[j] cnt = cnt + 1 x += 1 if cnt == 0: return x return x print(babble_sort(C)) if __name__ == '__main__': main()