_,W,_,B=[set(map(int,input().split())) for _ in [0]*4] w,b,c=1,1,0 for x in sorted(list(W|B)): if x in W&B:c+=1;w,b=b,w elif b*x in W:c+=1;w,b=1,0 elif w*x in B:c+=1;w,b=0,1 print(c)