#include<bits/stdc++.h>
#define I inline
using namespace std;
const int N=1e5+7;
int a[N],b[N],low[N],c[N];
int n,m,cnt;
int v[N],p[N];
map<int,int> mp;
I int read()
{
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-')f=-1;ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int main()
{
freopen("clyzzyq.in","r",stdin);
freopen("clyzzyq.out","w",stdout);
n=read(),m=read();
for (int i=1;i<=n;i++) a[i]=read(),mp[a[i]]=i;
for (int i=1;i<=m;i++)
{
b[i]=read(),p[i]=mp[b[i]];
if (p[i]) c[++cnt]=p[i];
}
int tot=1;low[tot]=c[tot];
if (!cnt) tot--;
for (int i=2;i<=cnt;i++)
{
if (c[i]>low[tot]) low[++tot]=c[i];
else
{
int pos=lower_bound(low+1,low+tot+1,c[i])-low;
low[pos]=c[i];
}
}
printf("%d\n",n+m-2*tot);
return 0;
}