#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 (int i = (int)a; i < (int)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define MOD 1000000007 #define INF 1000000000 #define PI 3.14159265359 #define EPS 1e-12 int dp[11234], n; bool use[11234]; void dfs(int num) { if(use[num]) return; int c = __builtin_popcount(num); //cout << "num:" << num << " c:" << c << endl; //FOR(i, 1, n+1) cout << dp[i] << " "; cout << endl; use[num] = true; if(num-c > 0) { //cout << "-" << endl; if(!use[num-c]) dp[num-c] = dp[num] + 1; dfs(num-c); } if(num+c <= n) { //cout << "+" << endl; if(!use[num+c]) dp[num+c] = dp[num] + 1; dfs(num+c); } return; } int main(void) { cin >> n; memset(dp, -1, 11234); dp[1] = 1; dfs(1); cout << dp[n] << endl; return 0; }