n, m = map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
q=min(a)
w=min(b)
e=list(set(a)&set(b))
if e==[]:
    if q>w:
        print(w*10+q)
    else:
        print(q*10+w)
else:
    print(min(e))