#include #include #include #include #include #include #include #include #include #include #include #include #include #define FOR(i, a, b) for(int i=(a);i<=(b);i++) #define RFOR(i, a, b) for(int i=(a);i>=(b);i--) #define MOD 1000000007 #define INF 1000000000 #define PI 3.14159265358979 using namespace std; typedef pair P; int main(void) { int n; queue

que; cin >> n; que.push(P(1,0)); while (1) { int a, deep; int b; int flag = 0; a = que.front().first; deep = que.front().second; b = a; if (deep > 1000) { cout << -1 << endl; break; } que.pop(); while (1) { if (b % 2 == 1) { flag++; } b /= 2; if (b == 0) { break; } } if (a + flag == n) { cout << deep + 1 << endl; break; } if (a - flag > 0) { que.push(P(a - flag, deep + 1)); } if (a + flag < n) { que.push(P(a + flag, deep + 1)); } } return 0; }