n,m=map(int,input().split())
t = set(map(int,input().split()))
r = set(map(int,input().split()))
q = min(t)
q1=min(r)
if q in r and q1 not in t:
    print(q)
elif q1 in t and q not in r:
    print(q1)
elif q in r and q1 in t and q < q1:
    print(q)
elif q in r and q1 in t and q1 <= q:
    print(q1)
else:
    if q < q1:
        print(q,q1,sep='')
    else:
        print(q1,q,sep='')