n, m = map(int, input().split())

a = sorted((map(int, input().split())))
b = sorted((map(int, input().split())))

k = [i for i in a if i in b]

if k:
    print(k[0])
elif a[0] < b[0]:
    print(a[0], b[0], sep='')
else:
    print(b[0], a[0], sep='')
