
input()

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

minimun = 10

for i in n:
    if i in m and i < minimun:
        minimun = i

if minimun != 10:
    print(minimun)
else:
    f = min(n[0], m[0])
    s = max(n[0], m[0])
    print('{}{}'.format(f, s))
