from functools import reduce import math a,b=map(int,input().split()) T=list(map(int,input().split())) S=list(map(int,input().split())) g1=reduce(math.gcd,T) g2=reduce(math.gcd,S) print("Yes" if g2%g1==0 else "No")