n, m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
mas = [10] * 10
v1 = min(a)
v2 = min(b)
for i in a:
    for j in b:
        if i == j:
            mas[i] = i
if min(mas) < 10:
    print(min(mas))
else:
    print(min(v1,v2), end = '')
    print(max(v1,v2))
