n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
for i in range(n):
    for j in range(m):
        if a[i] == b[j]:
            print(a[i])
            exit(0)
if a[0] > b[0]:
    print(str(b[0]) + str(a[0]))
else:
    print(str(a[0]) + str(b[0]))