lenghts = [int(i) for i in input().split()]
numbers1 = [int(i) for i in input().split()]
numbers2 = [int(i) for i in input().split()]
smaller1, smaller2 = 10, 10
for i in numbers1:
    if i<smaller1:
        smaller1 = i
for i in numbers2:
    if i<smaller2:
        smaller2 = i
if smaller1 == smaller2:
    print(smaller1)
else:
    print(str(smaller1)+str(smaller2))
  	 				  		  	 	 	 	   	  	 		