#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 visited(n + 1); vector cnt(n + 1); fill(visited.begin(), visited.end(), false); queue q; q.push(1); visited[1] = true; cnt[1] = 1; while(!q.empty()){ int now = q.front(); q.pop(); visited[now] = true; int dist = cntbit(now); if(now + dist >= 1 && now + dist <= n && !visited[now + dist]) { q.push(now + dist); cnt[now + dist] = cnt[now] + 1; } if(now - dist >= 1 && now - dist <= n && !visited[now - dist]) { q.push(now - dist); cnt[now - dist] = cnt[now] + 1; } } if(visited[n]) cout << cnt[n] << endl; else cout << -1 << endl; return 0; }