n, m = [int(x) for x in raw_input().split()]
l1 = [int(x) for x in raw_input().split()]
l2 = [int(x) for x in raw_input().split()]
l1.sort()
l2.sort()
min1 = l1[0]
min2 = l2[0]

mn = 1e9

for el in l1:
    if el in l2:
        mn = el
        break

if min1 == min2:
    print min1
elif mn != 1e9:
    print mn
else:
    l3 = [min1, min2]
    l3.sort()
    print str(l3[0]) + str(l3[1])
