d=0,-1,1,*[-1]*n=gets.to_i 3.upto(999){|p|2**p%p==2&&n.downto(p){|i|t=d[i-p]+1;t>0&&d[i]