#include using namespace std; int main(){ auto popcount=[](int n){int res=0;for(int i=0;i<30;i++) if((n>>i)&1) res++;return res;}; int n;cin>>n; vector ans(n+1,-1); queue que; ans[1]=1; que.push(1); while(!que.empty()){ int v=que.front(); que.pop(); int t=popcount(v); for(auto d:{-t,t}){ int nv=v+d; if(!(1<=nv&&nv<=n&&ans[nv]==-1)) continue; que.push(nv); ans[nv]=ans[v]+1; } }cout<