n,m = map(int, input().split())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
b = [0 for i in range(10)]
c=0
for i in range(n):
    b[a1[i]] = 1
for i in range(m):
    b[a2[i]] += 1
for i in range(10):
    if b[i] == 2:
        print(i)
        c = -1
        break
if c==0:
    print(min(min((a1)),min(a2)), max(min((a1)),min(a2)), sep = '')