#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ll N; cin >> N;
	ll a,b=0,c, ans=1e18;
	for(ll j=1; j<=N; b++,j=j*2){
		a = N/j;
		c = N%j;
		ans = min(ans, a+b+c);
	}

	cout << ans << endl;
	return 0;
}
#include<iostream>
using namespace std;

int main()
{
  	long long int num;
  	cin>>num;
    long long int ans =0;
  	long long int ans2;
    long long int one =1;
  	for(long long int i=0;num>(one<<(i-one));i++)
    {
      //(num&((2<<i)-1))
      if((ans<=(num-(num>>i)*(one<<i)))&&ans!=0)
      {
      break;
      }
      ans2=i+(num>>i)+(num-(num>>i)*(one<<i));

      if(ans>ans2||ans==0)
      {
      ans = ans2;
      }
    }
  cout<<ans;
	return 0;
}