#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define T third
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<pair<int,int>> vp;
typedef vector<long long> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvll;
const int C=1e9+7;
const int C1=998244353;
void yes(){	
    cout<<"YES\n";
}
void no(){
    cout<<"NO\n";
}
ll binpow(ll a, ll b, ll m=C) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
//Variables********************************************

//Functions********************************************

//*****************************************************
void solve(){
	ll n; cin>>n;
	ll ans=LLONG_MAX;
	for(int i=0;i<=60;i++){
		if(pow(2,i)>n) break;
		ll p=pow(2,i);
		ll r=n%p;
		ll c=(n-r)/p;
			ans=min(ans,i+c+r);
	}
	cout<<ans<<endl;
}

signed main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t=1; //cin>>t;
    int x{};
    while(t--){
    	//cout<<"Case #"<<x<<": "; x++;
        solve();
    }
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

ll tmp[600001], *A = tmp + 200000, *B = tmp + 400000;
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}
const int CM = 400001, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N = getint();
	rep(i, N) {
		A[i] = ll(i) << 32 | getint();
		B[i] = ll(i) << 32 | getint();
	}
	pakuri_sort(N, A);
	pakuri_sort(N, B);

	const ll ma = (1ll << 32) - 1;
	rep(i, N) {
		auto tmp = (A[i] & ma) < (B[N - 1 - i] & ma);
		cn[A[i] >> 31] = tmp;
		cn[B[N - 1 - i] >> 31 | 1] = tmp;
	}

	int c = -1, pn = 0;
	rep(i, N << 1) {
		if (c != -1 && pn == cn[i]) {
			cn[c] = '(';
			cn[i] = ')';
			c = tmp[c];
			pn ^= 1;
		}
		else {
			pn = cn[i];
			tmp[i] = c;
			c = i;
		}
	}
	fwrite(cn, 1, N << 1, stdout);

	Would you please return 0;
}