#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
   ll N;cin>>N;
   ll ans=N;
   for(ll b=0;(1LL<<b)<=N;b++){
      ll a = N/(1LL<<b);
      ll c = N - a*(1LL<<b);
      ans=min(ans,a+b+c);
      
   }

   cout<<ans<<endl;    


}


#include"bits/stdc++.h"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }
#define INF 1e18
#define PI (acos(-1))
#define mod (int)1e9+7
struct Edge {
    ll to, weight;
    Edge(ll t, ll w) :to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
int main() {
    string s;
    cin >> s;
    ll cnt = 0;
    REP(i, s.size() - 3) {
        if (s.substr(i, 4) == "ZONe") {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}