#include using namespace std; #define rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i> n; } void solve() { queue q; vector ans(n, -1); q.push(0), ans[0] = 1; while (not q.empty()) { const int v = q.front(); q.pop(); const int d = __builtin_popcount(v + 1); if (v - d >= 0 and ans[v - d] == -1) { q.push(v - d), ans[v - d] = ans[v] + 1; } if (v + d < n and ans[v + d] == -1) { q.push(v + d), ans[v + d] = ans[v] + 1; } } cout << ans[n - 1] << endl; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); input(); solve(); }