N = int(input()) B = list(map(int,input().split())) A = list(map(int,input().split())) C = {a:i for i,a in enumerate(A)} B = [C[b] for b in B] now = set() #print(B) for b in B: if b-1 in now: now.add(b) now.remove(b-1) else: now.add(b) n = len(now) ans = 0 while n>1: n = (n+1)//2 ans += 1 print(ans)