#include using namespace std; int cntbit(int x) { int ret = 0; while(x > 0){ if(x % 2 == 1) ret++; x /= 2; } return ret; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector cnt(n + 1); fill(cnt.begin(), cnt.end(), 1e9); queue q; q.push(1); cnt[1] = 1; while(!q.empty()){ int now = q.front(); q.pop(); int dist = cntbit(now); if(now + dist >= 1 && now + dist <= n && cnt[now + dist] == 1e9) { q.push(now + dist); cnt[now + dist] = cnt[now] + 1; } if(now - dist >= 1 && now - dist <= n && cnt[now - dist] == 1e9) { q.push(now - dist); cnt[now - dist] = cnt[now] + 1; } } if(cnt[n] != 1e9) cout << cnt[n] << endl; else cout << -1 << endl; return 0; }