#include using namespace std; #define all(v) v.begin(),v.end() using ll = long long; const ll INF=1ll<<60; int main(){ ll N; cin>>N; vector d(N+1,INF); d[1]=0; queue q; q.push({1}); while(!q.empty()){ auto x=q.front();q.pop(); auto a=__builtin_popcount(x); if(x-a>=1&&d[x-a]==INF){ d[x-a]=d[x]+1; q.push(x-a); } if(x+a<=N&&d[x+a]==INF){ d[x+a]=d[x]+1; q.push(x+a); } } if(d[N]==INF)d[N]=-2; cout << d[N]+1 << endl; }