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