#include using namespace std; int n; int memo[11111]; bool flg[11111]; int k; int solve(int p, int q){ if(p == n) return 1; if(p < 1 || p > n) return 1<<28; if(q == n) return 1<<28; if(memo[p]) return memo[p]; int cnt = 0; for(int i=0;i<32;i++) if((p & (1 << i))) cnt++; int ret = 0; ret += min(solve(p-cnt, q++), solve(p+cnt, q++)) + 1; return memo[p] = ret; } int main(){ int ans; cin >> n; ans = solve(1, 0); if(ans >= 1<<28) puts("-1"); else cout << ans << endl; }