n,m=input().split()
a=set(map(int, input().split()))
b=set(map(int, input().split()))
common=a&b
if len(common)>0:
    print(min(common))
else:  
    print(min(min(a), min(b))*10+max(min(a), min(b)))

