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 a:
    for j in b:
        if i == j:
            print(i)
            exit(0)

print(min(a[0],b[0]), max(a[0],b[0]), sep='')