#include using namespace std; using Int = int_fast64_t; using Word = uint_fast64_t; using Int128 = __int128_t; using Word128 = __uint128_t; using VInt = vector; using VVI = vector; using VWord = vector; using VVW = vector; using VS = vector; using VVS = vector; using VB = vector; using VVB = vector; using PII = pair; using PWW = pair; using VPII = vector; using VPWW = vector; #define SZ(x) ((Int)(x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define rep(i,n) for(Int i=0, i##_len=(n); i 0) { ret++; a &= a - 1; } return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); const Int inf = 1 << 30; Int n; cin >> n; VInt dp(n + 1, inf); dp[1] = 1; queue que; que.push(1); while(!que.empty()) { Int now = que.front(); que.pop(); Int move = bitcount(now); for (Int i = -move; i <= move; i += move * 2) { Int next = now + i; if (next < 1 || next > n) continue; if (dp[next] != inf) continue; dp[next] = dp[now] + 1; que.push(next); } } if (dp[n] == inf) cout << "-1\n"; else cout << dp[n] << '\n'; return 0; }