lixo = list(map(int, raw_input().split()))
lista_01 = list(map(int, raw_input().split()))
lista_02 = list(map(int, raw_input().split()))

minimo_01 = 10
minimo_02 = 10

for x in lista_01:
  if (x < minimo_01) and (x in lista_02):
    minimo_01 = x

for x in lista_02:
  if (x < minimo_02) and (x in lista_01):
    minimo_02 = x

if(minimo_01 == minimo_02):
  print(minimo_01)
else:
  print(str(minimo_01)+str(minimo_02))
 			 		 	  	 		 	 		 		 	  				