#include #define rep(i, n) for (int i=0; i<(n); i++) using namespace std; template inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; } template inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; } int dp[10101]; int main(){ int n; cin>>n; rep(i, n+1) dp[i] = 1e9; queue q; q.push(1); dp[1] = 1; while (!q.empty()){ int x = q.front(); q.pop(); int d = __builtin_popcount(x); if (x+d <= n) if (chmin(dp[x+d], dp[x]+1)) q.push(x+d); if (x-d > 0) if (chmin(dp[x-d], dp[x]+1)) q.push(x-d); } if (dp[n]>=1e9) cout<<-1<