n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort()
b.sort()
for i in range(1,10):
    if b.count(i) != 0 and a.count(i)!= 0:
        print(i)
        exit()

a = min(a)
b = min(b)
print(min(a,b),max(a,b),sep = '')