#CodeForces 870A
n, m = map(int, input().split())
a = set(map(int, input().split()))
b = set(map(int, input().split()))

x = min(a)
y = min(b)
e = a & b

if len(e) != 0:
    print(min(e))
else:
    print(min(x, y),max(x, y),sep = '')
