n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ac, bc = [0] * 10, [0] * 10
mn1 = min(a)
mn2 = min(b)
for i in range(n):
    ac[a[i]] += 1
for i in range(m):
    bc[b[i]] += 1
for i in range(10):
    if(ac[i] and bc[i]):
        print(i)
        exit()
if mn2 < mn1:
    mn1, mn2 = mn2, mn1
print(str(mn1) + str(mn2))