n, m = map(int, raw_input().split(' '))
a = map (int, raw_input().split(' '))
b = map (int, raw_input().split(' '))

ans = min(min(a) * 10 + min(b), min(b) * 10 + min(a))
for i in range(n):
    for j in range(m):
        if a[i] == b[j]:
            ans = min(ans, a[i])

print ans
