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]

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