q = [int(i) for i in input().split()]
N1 = [int(i) for i in input().split()]
N2 = [int(i) for i in input().split()]

N1.sort()
N2.sort()
c=0
for i in N1:
    if i in N2:
        print(i)
        c=1
        break
if c != 1:
    if N1[0] == N2[0]:
        print(N1[0])
    elif N1[0] > N2[0]:
        print(str(N2[0])+str(N1[0]))
    else:
        print(str(N1[0])+str(N2[0]))
		 					     	  	 				 		 		  	