n, m = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

mn=0
for i in range(1, 10):
    if (i in a) and (i in b):
        mn=i
        break

a = min(a)
b = min(b)

if mn: print(mn);
else: print(min(a, b), max(a, b), sep='');
