n=gets.to_i r=0,1 n.times{|i|r&[i]==[i]&&n.times{|j|r[j+x=('%b'%j).count(?1)]||=i+1;r[j-x]||=i+1}} p r[n]||~0