def least(list):
    l = list[0]
    for i in list:
        if i<l:
            l = i
    return l

#----------------------
str1 = raw_input().split()
n = int(str1[0])
m = int(str1[1])
list1 = []
str1 = raw_input().split()
for a in str1:
    list1.append(int(a))
list2 = []
str1 = raw_input().split()
for a in str1:
    list2.append(int(a))
#----------------------

join=list(set(list1) & set(list2))
if len(join)>0:
    print(least(join))
else:
    a = least(list1)
    b = least(list2)
    if(a<b):
        print(str(a) + str(b))
    else:
        print(str(b) + str(a))

