n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
if n<m:
    for elem in a:
        if elem in b:
            c.append(elem)
else:
    for elem in b:
        if elem in a:
            c.append(elem)
if min(a)<min(b):
    v=int(str(min(a))+str(min(b)))
else:
    v=int(str(min(b))+str(min(a)))
if len(c)!=0:
    if v<min(c):
        print(v)
    else:
        print(min(c))
else:
    print(v)
