#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define mod 1e9+7
#define ff first
#define ss second
#define ins insert
#define endl "\n"
#define pie_op ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define tc int t;cin>>t;while(t--)
#define pb push_back
#define input(n) int arr[n];for(int i1=0;i1<n;i1++)cin>>arr[i1]

int main()
{
	pie_op;
	ll n, ans = INT_MAX;
	cin >> n;
	for(int i = 0; i <= 60; i++){
		ll b = i;
		ll a = n / (1LL << b);
		ll c = n - a * (1LL << b);
		ans = min(ans, a + b + c);
	}
	cout << ans;
	return 0;
}
#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong N;
  cin >> N;

  llong ans = inf;
  for (llong b = 0; b <= 60; b++) {
    llong a = N / (1ll << b);
    llong c = N % (1ll << b);
    ans = min(ans, a + b + c);
  }

  cout << ans << endl;

  return 0;
}