#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
const int inf=1e9+7;
const ll INF=9e18/2;
const long double PI = acosl(-1.0);
const long double EPS=1e-10;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
bool pair_comp(const pair<long,long> &A,const pair<long,long> &B){if(A.first==B.first)return A.second>B.second;return A.first<B.first;}//F昇→S降
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){//cout<<fixed<<setprecision(20);
  ll n;
  cin>>n;
  ll ans=INF;
  ll t=1;
  rep(b,0,70){
    if(t>n)break;
    ll a,c;
    a=n/t;
    c=n%t;
    chmin(ans,a+b+c);
    t*=2;
  }
  cout<<ans<<endl;
}
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <vector>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
// mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; i < n; i++)
#define sr(i, n) for (i = 0; i < n.length(); i++)

// template<typename... T>
// void read(T&... args) {
// 	((cin >> args), ...);
// }

// // template<typename... T>
// // void write(T&&... args) { //rvalue reference is new to C++
// // 	((cout << args << " "), ...);
// // }

void rank0001()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     //freopen("input.txt", "r", stdin);
    //     //freopen("output.txt", "w", stdout);
    // #endif
}

int main()
{
    rank0001();
    ll n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++)
    {
        if (i + 2 != s.length())
        {
            if (s[i] == 'f' && s[i + 1] == 'o' && s[i + 2] == 'x')
            {
                s.erase(i, 3);
                if (i == 0 || i == 1 || i == 2)
                    i = -1;
                else
                    i -= 3;
            }
        }
        //cout << s.length();
    }
    cout << s.length() << endl;
}