c = input().split()
a = int(c[0])
b = int(c[1])
n = [int(i) for i in input().split()]
m = [int(i) for i in input().split()]
c = set.intersection(set(n),set(m))   
if(len(c)==0):
    print(min(min(n),min(m)),max(min(n),min(m)),sep="")
else:
    print(min(list(c)))
