n,m=map(int, input().split())
a=[int(n) for n in input().split()]
b=[int(m) for m in input().split()]
a=sorted(a)
b=sorted(b)
c=set(a)
d=set(b)
l=set()
if c&d!=l:
    l=c&d
    l=sorted(l)
    print(l[0])
else:
    if a[0]>b[0]:
        print(b[0],a[0],sep='')
    else:
        print(a[0],b[0],sep='')


    