n, m = raw_input().split(" ")
a = raw_input().split(" ")
b = raw_input().split(" ")
menora = a[0]
menorb = b[0]

for i in a:
    if i < menora:
        menora = i
for i in b:
    if i < menorb:
        menorb = i

if menora == menorb:
    print(menora)
else:
    print("{}{}".format(menora, menorb))
  		 	  						   		  	  	   	