N,Q=map(int, input().split()) A=list(map(int, input().split())) B=list(map(int, input().split())) D={} for i in range(N): b=A[i] if b not in D: D[b]=[] D[b].append(i) dp=[10**10]*N dp[0]=0 for b in B: nex=D[b] L=[10**10]*N;R=[10**10]*N;ndp=[10**10]*N l=10**10;r=10**10 for i in range(N): l=min(dp[i],l+1) if A[i]==b: ndp[i]=min(ndp[i],l) j=-1-i r=min(dp[j],r+1) if A[j]==b: ndp[j]=min(ndp[j],r) dp=ndp print(min(dp))