#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define rng(a) a.begin(),a.end() using namespace std; typedef long long int ll; typedef pair P; typedef vector vi; typedef vector vvi; typedef vector vl; typedef vector

vp; #define dame { puts("-1"); return 0;} #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 int popcnt(uint32_t bits) { int ret; __asm__ ("popcntl %[input], %[output]" : [output] "=r"(ret) : [input] "r"(bits)); return ret; } int main() { int n; cin >> n; int ans[n+1] = {}; rep(i,n+1)ans[i] = -1; queue que; que.push(1); ans[1] = 1; while(!que.empty()){ int x = que.front(); que.pop(); int cnt = popcnt(x); if(0 < x-cnt && ans[x-cnt] == -1){ ans[x-cnt] = ans[x] + 1; que.push(x-cnt); } if(x+cnt <= n && ans[x+cnt] == -1){ ans[x+cnt] = ans[x] + 1; que.push(x+cnt); } } cout << ans[n] << endl; return 0; }