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