#include #include #define YES cout<<"Yes"<; using vvl = vector>; using vvvl = vector>>; //sample vvvl A(N,vvl(N,vl(N,0))); const ll POW2=1e2,POW5=1e5,POW6=1e6,POW9=1e9,POW12=1e12,POW15=1e15,POW18=1e18; const int iINF = 1<<30; const ll INF = 1LL<<62; const ull UINF = 1LL<<63; const ld ldINF=(ld)POW15; const ll mod=998244353; const ll mod2=1000000007; const ld PI=3.141592653589793238462643; vector dy={-1,0,1,0},dx={0,1,0,-1},dy8={-1,-1,-1,0,0,1,1,1},dx8={-1,0,1,-1,1,-1,0,1}; template using pq = priority_queue>; template using pq_g = priority_queue,greater>; templatebool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } templatevoid vc_unique(vector &v){v.erase(unique(v.begin(),v.end()),v.end());} templatevoid sdebug(string s, T& a){cout<void vdebug(string s, vector &v){ ll W=v.size(); cout<<"--------------------------"<POW15) cout<<"INF "; else if(v[i]<-POW15) cout<<"-INF "; else cout<void vvdebug(string s, vector> &v){ ll H=v.size(); cout<<"--------------------------"<POW15) cout<<"INF "; else if(e<-POW15) cout<<"-INF "; else cout<=0 && n%m!=0) return n/m+1; else return n/m; } ll truncate(ll n, ll m){ if(n<0 && n%m!=0) return n/m-1; else return n/m; } int main() { std::cin.tie(0)->sync_with_stdio(0); ll N;cin>>N; queue q; vl dist(N+1,INF); q.push(1); dist[1]=1; while(!q.empty()){ ll pos=q.front();q.pop(); ll p=__builtin_popcount(pos); if(pos+p<=N && dist[pos+p]==INF){ dist[pos+p]=dist[pos]+1; q.push(pos+p); } if(pos-p>0 && dist[pos-p]==INF){ dist[pos-p]=dist[pos]+1; q.push(pos-p); } } if(dist[N]==INF) cout<<-1<