n, m = map(int, input().split())
a = set(list(map(int, input().split())))
b = set(list(map(int, input().split())))
min1 = min(a)
min2 = min(b)
for i in a:
    for j in b:
        if i == j:
            print(i)
            exit()
            
if min1 < min2:
    print(min1,min2, sep = '')
elif min1 > min2:
    print(min2,min1, sep = '')
else:
    print(min1)
