x,y = map(int, raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
m = list(set(a).intersection(b))
if len(m) != 0:
  print m[0]
else:
  x = min(a)
  y = min(b)
  if x > y:
    print ('%d%d') %(y,x)
  elif x < y:
    print ('%d%d') %(x,y)
 	 	 		 		 			  	 				 			   	