n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.sort()
a.sort()
for i in a:
    if i in b:
        print(i)
        exit()
c= []
c.append(a[0])
c.append(b[0])
c.sort()
print(*c,sep="")
