n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = min(a)
y = min(b)
if x not in b and y not in a:
    print(str(x)+str(y))
elif x not in b and y in a:
    a.pop(a.index(y))
    b.pop(b.index(y))
    y = min(b)
    print(str(x)+str(y))
elif x in b and y not in a:
    b.pop(b.index(x))
    a.pop(a.index(x))
    x = min(a)
    print(str(x)+str(y))
else:
    print(1)
