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 = mn2 = 1e9
for i in range(n):
    ac[a[i]] += 1
    mn1 = min(mn1, a[i])
for i in range(m):
    bc[b[i]] += 1
    mn2 = min(mn2, b[i])
for i in range(10):
    if(ac[i] and bc[i]):
        print(i)
        exit()
print(str(min(mn1, mn2)) + str(max(mn1, mn2)))