inp = input()
list1 = input()
list1 = list1.split(' ')
list2 = input()
list2 = list2.split(' ')
min1 = 10
fl = 0
extra = 10
for i in list1:
    for j in list2:
        if (i == j) and (int(i) < extra):
            fl = 1
            extra = int(i)
if fl == 1:
    print(extra)
else:
    for i in list1:
        if min1 > int(i):
            min1 = int(i)
    min2 = 10
    for j in list2:
        if min2>int(j):
            min2 = int(j)
    if min1>min2:
        print(str(min2)+str(min1))
    elif min1<min2:
        print(str(min1)+str(min2))
    else:
        print(min2)
