lens = input().split()
l1 = input().split()
l2 = input().split()

min1, min2 = min(l1), min(l2)
result = ''
intersects = set(l1) & set(l2)

if len(intersects) != 0:
    result = min(intersects)
else:
    result = min([min1, min2]) + max([min1, min2]) 

print(result)
 		  				   		  		 		   	  				