n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=sorted(a)
b=sorted(b)
if(a[0]==b[0]):
    print(a[0])
elif(len(a)==1 and b.count(a[0])>=1):
    print(a[0])
elif(len(b)==1 and a.count(b[0])>=1):
    print(b[0])
else:
    print(min(int(str(a[0])+str(b[0])),(int(str(b[0])+str(a[0])))))
