#include #include #include #include #include #include #include #include #include #include #define FORR(i, a, b) for(int (i) = (a); (i) < (b); (i)++) #define REP(i, n) FORR(i, 0, n) #define mp make_pair; using namespace std; int mylog(long long x) { int s = 0; while (x > 1) { x >>= 1; s++; } return s; } long long mypow(int e) { long long s = 1; while (e--) { s <<= 1; } return s; } int main() { long long n; while (cin >> n) { if (n == 1) cout << "1\n"; else if (n <= 3) cout << "2\n"; else if (n == 5 || n == 6) cout << n - 2 << endl; else { int ans = mylog(n + 1); int h = ans; n -= mypow(ans) - 1; int tans = -1; long long nn = n; while (n) { tans = mylog(n); n -= mypow(tans); } if (tans >= 0) { ans += h - tans; if (nn < mypow(h - 1)) ans--; } cout << ans << endl; } } return 0; }