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 = min(lista_01)
minimo_02 = min(lista_02)

if(minimo_01 == minimo_02):
  print(minimo_01)
elif(minimo_01 != minimo_02 and minimo_01 in lista_02):
  print(minimo_01)
elif(minimo_01 != minimo_02 and minimo_02 in lista_01):
  print(minimo_02)
else:
  print(str(minimo_01)+str(minimo_02))
								   	 	 		     			   	 	