#include using namespace std; int main(){ int n; cin >> n; vector dist(n+1); for(int i=1;i<=n;i++){ dist[i]=-1; } dist[1]=1; queue q; q.push(1); while(q.size()){ int qf=q.front(); q.pop(); int cb=0; for(int i=qf;i!=0;i>>1){ if(i&1==1){ cb++; } } int dx[]={1,-1}; for(int i=0;i<2;i++){ int x=qf+cb*dx[i]; if(x>0&&x<=n&&dist[x]==-1){ dist[x]==dist[qf]+1; q.push(x); } } } if(dist[n]==-1){ cout << -1<