(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
for i in range(n):
    for j in range(m):
        if a[i] == b[j]:
            print(a[i])
            exit()
print(min(a[0], b[0]) * 10 + max(a[0], b[0]))