lenghts = [int(i) for i in input().split()]
numbers1 = [int(i) for i in input().split()]
numbers2 = [int(i) for i in input().split()]
numbers1.sort()
numbers2.sort()
c = 0
for i in range(len(numbers1)):
    if numbers1[i] in numbers2:
        print(numbers1[i])
        c = 1
        break
if numbers1[0]<numbers2[0] and c==0:
    print(str(numbers1[0])+str(numbers2[0]))
elif c==0:
    print(str(numbers2[0])+str(numbers1[0]))

 	 											 	 	  	 			 	 		