#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, init, end) for(ll i = init; i < end; i++)
#define REP(i, init, end) for(ll i = init; i < end + 1; i++)
#define rev(i, end, init) for(ll i = init - 1; i >= end; i--)
#define REV(i, end, init) for(ll i = init; i >= end; i--)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


#define INF 2000000000000000000

ll p(ll n, ll m){
    if(m == 0) return 1;
    if(m == 1) return n;
    if(m % 2 == 0){
        return p(n * n, m / 2);
    }
    return n * p(n * n, (m - 1) / 2);
}

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

    ll a, b, c;
    ll twoB;
    ll ans = INF;
    rep(i, 0, 62){
        b = i;
        twoB = p(2, b);
        if(twoB > N){
            break;
        }

        a = N / twoB;
        c = N % twoB;
        ans = min(ans, a + b + c);
    }

    cout << ans << endl;

    return 0;
}

# include<iostream>
# include <algorithm>
# include <queue>
# include <vector>
using namespace std;

int n;
long long a[200010],b[200010];
long long c[200010];
int main(void)
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    scanf("%lld",&a[i]);
    for (int i=1;i<=n;i++)
    scanf("%lld",&b[i]);
    long long ans = 0;
    long long maxa=0,maxb=0;
    for (int i=1;i<=n;i++)
    {
        ans = max(ans,a[i]*b[i]);
        ans = max(ans,maxa*b[i]);
        // ans = max(ans,maxb*a[i]);
        c[i] = ans;
        maxa = max(maxa,a[i]);
        // maxb = max(maxb,b[i]);
    }
    for (int i=1;i<=n;i++)
    printf("%lld\n",c[i]);
    return 0;
}