I,R,O=input,range,print L=9**5 P=[] C=[0]*L for i in R(2,L): if C[i]<1: P+=[i] j=i*i while j1:D+=[e] r=len(D)-1 while r and D[r-1]>=A:r-=1 print(max(D[r]-A,-1)if e else 0)