#include using namespace std; typedef long long ll; typedef vector VI; typedef vector VVI; typedef vector VL; typedef vector VVL; typedef pair PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define MOD 1000000007 #define INF (1LL<<25) //33554432 #define PI 3.14159265359 #define EPS 1e-12 //#define int ll signed main(void) { int n; cin >> n; int d[10010]; REP(i, n+1) d[i] = INF; queue que; que.push(1); d[1] = 1; while(que.size()) { int p = que.front(); que.pop(); //cout << p << endl; if(p == n) break; int n1 = p + __builtin_popcount(p), n2 = p - __builtin_popcount(p); if(0 < n1 && n1 <= n && d[n1] == INF) { que.push(n1); d[n1] = d[p] + 1; } if(0 < n2 && n2 <= n && d[n2] == INF) { que.push(n2); d[n2] = d[p] + 1; } } //REP(i, n+1) cout << d[i] << " "; cout << endl; if(d[n] == INF) cout << -1 << endl; else cout << d[n] << endl; return 0; }