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

l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))

ans = []

for i in l1:
    for j in l2:
        if i == j:
            ans.append(i)

if len(ans):
    print(min(ans))
else:
    print(*sorted((min(l1), min(l2))), sep='')
