#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define lld long double
#define ul  unsigned long int
#define pii pair<int,int>
#define pll pair<lli, lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ss  second
#define ff first
#define INF 1000000001
#define inf1 1000000000000000001
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int tc;cin>>tc;while(tc--)
#define clean(x,y) memset(x,y,sizeof(x))

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.ff << ", " << p.ss << ")"; }
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
	cin >> p.first;
	return cin >> p.second;
}
void caseNumber(int x){printf("Case %d: ",x);}
void yes(){cout<<"YES\n";}
void no(){cout<<"NO\n";}
int gray_code(int n) {return n ^ (n >> 1);}
int turnOn(int x,int pos) {return x | (1<<pos);}
int turnOff(int x,int pos){return x & !(1<<pos);}
bool isOn(int x,int pos) {return (bool)(x & (1<<pos));}
/// RULESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS////
/// READ THEM ALOUD......................................................................................................
/// 1. Read the problem at least twice
/// 2. Brute force if contraints r low
/// 3. Check base cases or break case if found any T-T
/// 4. Can u force it into some algorithms?
/// 5. Can u relate it to some previous stuff?
/// 6. :D :) :V :3

lli const mod= 1e9+7;
lli const inf=1e9+9;
//lli const mod=998244353;
lli const maxn=3e5+7;



int main()
{
    int n;cin>>n;
    cout<<n-1<<endl;
}

#include <bits/stdc++.h>
#define int long long
#define menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi pair<int, int>
#define BE(i) i.begin(),i.end()
#define fi first
#define se second
#define INF 2147483647
#define mkp make_pair
#define ist insert
#define mod 1000000007
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC optimize("O2")
using namespace std;
int min(int a, int b){return a < b ? a : b;}
int max(int a, int b){return a > b ? a : b;}
bool isprime(int k){bool is=1 ; for ( int i = 2 ; i*i <= k ; i++ ) if ( k % i == 0 ) is = 0 ; return k>1?is:0;}
const double PI=acos(-1);
int n;

inline void sol(){
    cin >>n;
    int ans=n,r=2;
    for (int i=1;i<=60;i++){
        if (r>n) break;
        ans=min(ans,i+n/r+n%r);
        r*=2;
    }
    cout <<ans;
}
signed main(){
    menhera_chan_is_mine
    int _=1;
    //cin >>_;
    while (_--) sol();
    return 0;
}
