#include #include using namespace std; int bpop(int n){ int m=n%2; for(;n/=2;)m+=n%2; return m; } int main(){ int a[10001]={0,1},n,i=1,flag=-1; queue que; cin>>n; que.push(i); while (1){ if (i==n) { flag = 0; break; } if (i-bpop(i) > 1 && i-bpop(i) <= n) { a[i-bpop(i)] = a[i] + 1; que.push(i-bpop(i)); } if (i+bpop(i) > 1 && i+bpop(i) <= n) { a[i+bpop(i)] = a[i] + 1; que.push(i+bpop(i)); } que.pop(); if (que.empty()) break; i=que.front(); } if (flag) cout<<-1<<"\n"; else cout<