a,b = map(int, raw_input().split())
x = map(int, raw_input().split())
y = map(int, raw_input().split())
if min(x) == min(y):
  print (min(x))
elif min(x) > min(y):
  print ('%d%d') %(min(y),min(x))
elif min(x) < min(y):
  print ('%d%d') %(min(x),min(y))


	 		 			 				 		 	 	  		 		   	