n,m=map(int,input().split())
a=[]
a=(input().split())
b=input().split()
for i in range(len(a)):
    a[i]=int(a[i])
a.sort()
for i in range(len(b)):
    b[i]=int(b[i])
b.sort()
for i in a:
    for j in b:
        if i==j:
            print(i)
            exit()
if a[0]<b[0]:
    print(str(a[0]) + str(b[0]))
else:
    print(str(b[0]) + str(a[0]))
