N,Q=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) T={} C=set(A) C=list(C) C.sort() for i in range(len(C)): T[C[i]]=i M=len(C) R=[set() for i in range(M)] for i in range(N): R[T[A[i]]].add(i) L=[0] dp=[[10**15]*N for i in range(Q+1)] dp[0][0]=0 from bisect import bisect_right for i in range(Q): L2=[] for j in range(N): if A[j]==B[i]: L2.append(j) pos=bisect_right(L,j) if pos>0: dp[i+1][j]=min(dp[i][L[pos-1]]+j-L[pos-1],dp[i+1][j]) if pos