#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = 1e9;
const ll LIN = 1e18;

int main() {
  ll N;
  cin >> N;
  ll ans = LIN;
  for (ll i = 0; i < 64;i++) {
    ll b = ((ll)1 << i);
    ll a = N / b, c = N % b;
    ans = min(ans, a + i + c);
  }
  cout<<ans<<endl;
}
#include<iostream>

using namespace std;

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

	cout << N - 1 << endl;

	return 0;
}