n,m=map(int,input().split())
s=list(map(int,input().split()))
s.sort()
ss=list(map(int,input().split()))
ss.sort()
p=[]
if n>=m:
    l=n
else:
    l=m
for n in range(l):
    if n>=m:
        if s[n] in ss:
            print(s[n])
            break
    else:
        if ss[n] in s:
            print(ss[n])
            break

else:
   if s[0]<=ss[0]:
    print(str(s[(0)])+str(ss[0]))
   else:
       print(str(ss[0])+str(s[0]))
    