#include using namespace std; #define fastcin {\ cin.tie(0);\ ios::sync_with_stdio(false);\ } //#define rep(i, a, b) for(int i = a; i < b; i++) #define REP(i, a) for(int i = 0; i < a; i++) #define scan(x) cin >> n; #define print(x) cout << x << "\n" int countbit(int n) { int count = 0; for (int i = 1; i < n + 1; i <<= 1) if (n & i) count++; return count; } int main() { fastcin; int n; scan(n); int masu[10001], turn[500][500]; REP(i, 10001) masu[i] = 10002; int locate, count = 1, branch = 1, ans = -1; turn[count][branch] = 1; masu[1] = 1; int move, p ,m, next; if (n != 1) { for (int i = 1; i <= count; i++) { next = 1; for (int j = 1; j <= branch; j++) { locate = turn[i][j]; move = countbit(locate); p = locate + move; m = locate - move; if (p == n || m == n) { ans = i; break; } if (masu[p] == 10002 && p < n) { masu[p] = i++; turn[i+1][next] = p; next++; } else if (masu[m] == 10002 && m > 0) { masu[m] = i++; turn[i+1][next] = m; next++; } } if (next > 1) count++; branch = next; } } else ans = 1; print(ans); return 0; }