n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = str(min(min(a), min(b))) + str(max(min(a), min(b)))
y = 100
for i in range(n) :
    if a[i] in b and a[i] < y:
        y = a[i]
print(min(int(x), y))
