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

if ma > mb:
    ma, mb = mb, ma
    a, b = b, a
if ma in b:
    res = ma
elif mb in a:
    res = mb
else:
    res = ma * 10 + mb

print(res)
