#include <bits/stdc++.h>

using namespace std;

int main()
{
    unsigned long long n, res = 1e18; cin >> n;
    for (int i = 63; i >= 0; i--)
        res = min(res, n / (1ll << i) + i + n % (1ll << i));
    cout << res;
}
#include <bits/stdc++.h>
using namespace std;

typedef multiset<string> mss;
typedef map<int, int> mii;
typedef set<string> ss;
typedef vector<int> vi;

int main(void){
		string S;
		cin >> S;
		string T;

    bool isReverse = false;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'R') isReverse = !isReverse;
        else {
					if(isReverse) {
                T = S[i] + T;
                int l = T.size();
                if(l > 1 && T[0] == T[1]) {
                    // console.log(T.substr(0, l-2))
                    T = T.substr(2);
                }
          } else {
              T += S[i];
              int l = T.size();
              if(l > 1 && T[l-2] == T[l-1]) {
                  // console.log(T.substr(0, l-2))
                  T = T.substr(0, l-2);
              }
          }
        }
    }

    auto print = [](string s, bool isReverse) {
    	if(isReverse) {
    		reverse(s.begin(), s.end());
	    	for(char c: s) cout << c;
    	} else {
	    	for(char c: s) cout << c;
    	}
    };
    print(T, isReverse);
}
