#define il inline
#define ri register int
#include<cstdio>
#include<iostream>
using namespace std;
const int N=1005;
il int re(){
ri x=0,w=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*w;
}
int n,m,Ans,a[N],b[N],f[N];
int main(){
freopen("lcis.in","r",stdin);
freopen("lcis.out","w",stdout);
n=re();for(ri i=1;i<=n;i++)a[i]=re();
m=re();for(ri i=1;i<=m;i++)b[i]=re();
for(ri i=1;i<=n;i++){
ri Max=0;
for(ri j=1;j<=m;j++){
if(a[i]>b[j])Max=max(Max,f[j]);
if(a[i]==b[j])f[j]=Max+1;
}
}
n=max(n,m);
for(ri i=1;i<=n;i++)Ans=max(Ans,f[i]);
printf("%d\n",Ans);
return 0;
}