lens = [int(i) for i in input().split()]
s1 = [int(i) for i in input().split()]
s2 = [int(i) for i in input().split()]
min1 = min(s1)
min2 = min(s2)
if list(set(s1) & set(s2)) != []:
    print(list(set(s1) & set(s2))[0])
elif min1 == min2:
    print(min1)
else:
    print(min(min1, min2)*10 + max(min1, min2))
