n,m=map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
z=-1
for i in range(9):
    if (((i+1) in a) and ((i+1) in b)):
        z=i+1
        break
if z!=-1:
    print(z)
else:
    print(min(min(b),min(a))*10+max(min(a),min(b)))
