n,m = map(int,input().split()) 
a = set(map(int,input().split()))
b = set(map(int,input().split()))
if a.isdisjoint(b):
    x=min(a)
    y=min(b)
    print(min(10*x+y,10*y+x))
else:
    c = a.intersection(b)
    print(min(c))
