n=gets.to_i d={1=>1} q=[1] ( u=q.shift h=u.to_s(2).count(?1) [u+h,u-h].map{|v| d[v]||0<v&&v<=n&&(d[v]=d[u]+1;q<<v) } )while q!=[] p d[n]||-1