n = [int(i) for i in input().split()]
list_n1 = [int(i) for i in input().split()]
list_n2 = [int(i) for i in input().split()]
list_n1.sort()
list_n2.sort()
con=0
for i in list_n1:
    if i in list_n2:
        print(i)
        con=1
        break
if con != 1:
    if list_n1[0] == list_n2[0]:
        print(list_n1[0])
    elif list_n1[0] > list_n2[0]:
        print(str(list_n2[0])+str(list_n1[0]))
    else:
        print(str(list_n1[0])+str(list_n2[0]))
 		  					 			 	 	 	 							 	