#include using namespace std; int n; int memo[10010]; void rec(int x, int d) { if (memo[x] > 0) return; memo[x] = d; int cnt = 0; for (int i = 0; x >> i; i++) { cnt += (x >> i & 1); } if (x - cnt > 0) rec(x - cnt, d + 1); if (x + cnt <= n) rec(x + cnt, d + 1); } int main(void) { cin >> n; memset(memo, -1, sizeof(memo)); rec(1, 1); cout << memo[n] << endl; return 0; }