n,m=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
e=min(a)
f=min(b)
if(e!=f):
    if(e<f):
        print(str(e)+str(f))
    elif(e>f):
        print(str(f)+str(e))
else:
    print(e)