n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort()
for i in range(1,10):
    if i in a and i in b:
        print(i)
        exit()
for i in range(10,101):
    if i // 10 in a and i % 10 in b or i // 10 in b and i % 10 in a:
        print(i)
        break
