#include "bits/stdc++.h" using namespace std; int n; bool check[10000]; int dfs(int now) { if (now == n) { return 1; } if(now < 1 || n < now || check[now]) { return -1; } check[now] = true; int cnt = 0, c = now; while (c) { cnt++; c &= c - 1; } int score1 = dfs(now + cnt); int score2 = dfs(now - cnt); if (~score1 && ~score2) { return min(score1, score2) + 1; } if(~score1) { return score1 + 1; } if(~score2) { return score2 + 1; } return -1; } static void solve() { cin >> n; cout << dfs(1) << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(); solve(); }