input()
l1=[*map(int,input().split())]
l2=[*map(int,input().split())]
f=list(set(l1).intersection(set(l2)))
if len(f)>0:
    print(min(f))
else:
    a=min(l1)
    b=min(l2)
    print(min(a,b),max(a,b),sep="")
'''
4 5
3 2 4 5
1 6 5 9 8
'''