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