n, m = input().split()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dup = []
c = min(a)
d = min(b)

for i in a:
    if(i in b):
        dup.append(i)

if(len(dup) > 0):
    print(min(dup))
else:
    print(str(min(c, d))+str(max(c, d)))

  	 	     	 			 		  	 			  		 	