input();c=lambda: list(map(int,input().split()));k=(c());k1=c();d=set(set(k).intersection(set(k1)));z=min(k);z1=min(k1)
try:print(min(int(str(min(z,z1))+str(max(z,z1))),int(str(min(d)))))
except:print(int(str(min(z,z1))+str(max(z,z1))))