#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef array<int,2> ar; signed main(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n; cin>>n; n++; bool used[n]={}; int d[n]={}; for(int i=0;i<n;i++) d[i]=1e9; d[1]=1; priority_queue<ar,vector<ar>,greater<ar>> pq; pq.push({1,1}); while(pq.size()){ ar p = pq.top(); pq.pop(); if(used[p[1]]) continue; used[p[1]]=1; int cnt = 0; d[p[1]]=min(d[p[1]],p[0]); for(int i=0;i<20;i++){ if(p[1] & (1<<i)) cnt++; } if(p[1]+cnt<n && !used[p[1]+cnt]) pq.push({p[0]+1,p[1]+cnt}); if(p[1]-cnt>1 && !used[p[1]-cnt]) pq.push({p[0]+1,p[1]-cnt}); } if(d[n-1]==1e9)cout<<-1<<endl; else cout << d[n-1] << endl; }