#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,p,m; queue que; cin>>n; que.push(i); while (1){ if (i==n) { flag = 0; break; } p = i+bpop(i)>n?0:i+bpop(i); m = i-bpop(i)>1?i-bpop(i):0; if (p&&m&&a[p]&&a[m]) { que.pop(); i=que.front(); continue; } if (p && !a[p]) { a[p] = a[i] + 1; que.push(p); } if (m && !a[m]) { a[m] = a[i] + 1; que.push(m); } que.pop(); i=que.front(); if (que.empty()) break; } if (flag) cout<<-1<<"\n"; else cout<