n, m = map(int,(input().split()))
k = 0
l = map(int,(input().split()))
l11 = []
l22 = []
l2 = map(int,(input().split()))
l3 = []
for i in l:
    l11.append(i)
for i in l2:
    l22.append(i)
l11.sort()
l22.sort()
l3.append(l11[0])
l3.append(l22[0])
l3.sort()
for ev in l11:
    for ev2 in l22:
        if (ev == ev2):
            print(ev)
            k = 1
            break
    if (k == 1):
        break
if (k == 0):
    if (l3[0] == l3[1]):
        print(l3[0])
    else:
        print(int(str(l3[0]) + str(l3[1])))
