#include "bits/stdc++.h" using namespace std; typedef long long Int; #define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i)) int dp[10000 + 1]; int main() { int N; cin >> N; fill(dp, dp + 10001, -1); dp[1] = 1; queue q; q.push(1); while (!q.empty()) { int x = q.front(); q.pop(); int d = __builtin_popcount(x); if (x - d > 0) { if (dp[x - d] == -1) { dp[x - d] = dp[x] + 1; q.push(x - d); } } if (x + d <= N) { if (dp[x + d] == -1) { dp[x + d] = dp[x] + 1; q.push(x + d); } } } cout << dp[N] << endl; }