n,m = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

good = 0
res = 0
for i in range(1, 10):
    if i in a and i in b:
        good = 1
        res = i
        break

x = min(a)
y = min(b)
if (good):
    print(res)
else:
    print(min(x, y), end = '')
    print(max(x, y))