n=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
am=min(a)
bm=min(b)
c=0
for i in range(10):
    if (i in a) and (i in b):
        c=i
        break
if c!=0:
    print(c)
elif bm>am:
    print (am,bm,sep='')
elif   am>bm:
    print (bm,am,sep='')
