#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 n + 1; } check[now] = true; int cnt = 0, c = now; while (c) { cnt++; c &= c - 1; } return min(dfs(now + cnt), dfs(now - cnt)) + 1; } static void solve() { cin >> n; int ans = dfs(1); if (n < ans) ans = -1; cout << ans << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(); solve(); }