#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 main() { int n; cin >> n; int a[11234]; REP(i, n+1) a[i] = -1; a[1] = 1; queue que; que.push(1); while(!que.empty()) { int i = que.front(); que.pop(); int cnt = __builtin_popcount(i); if(i-cnt >= 1 && a[i-cnt] == -1) { a[i-cnt] = a[i] + 1; que.push(i-cnt); } if(i+cnt <= n && a[i+cnt] == -1) { a[i+cnt] = a[i] + 1; que.push(i+cnt); } } cout << a[n] << endl; }