#include <bits/stdc++.h>
using namespace std;
#define pi 3.1415926536
#define ll long long int
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
int main(){
fastio
 
    ll n;
    cin>>n;

    ll res=(1LL<<60);
    ll a,b,c;
    for(int i=0;i<60;i++){
        //cout<<a<<b<<c<<endl;
        b=i;
        a=n/(1LL<<i);
        c=n-(a*(1LL<<i));
        
        res=min(res,a+b+c);

    }
    cout<<res<<endl;
    return 0;
}
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include <functional>
template <typename T>
inline void hash_combine(std::size_t &seed, const T &val) {
    seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
template <typename T> inline void hash_val(std::size_t &seed, const T &val) {
    hash_combine(seed, val);
}
template <typename T, typename... Types>
inline void hash_val(std::size_t &seed, const T &val, const Types &... args) {
    hash_combine(seed, val);
    hash_val(seed, args...);
}
template <typename... Types>
inline std::size_t hash_val(const Types &... args) {
    std::size_t seed = 0;
    hash_val(seed, args...);
    return seed;
}
struct pair_hash {
    template <class T1, class T2>
    std::size_t operator()(const std::pair<T1, T2> &p) const {
        return hash_val(p.first, p.second);
    }
};
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define G 3
#define MAX_N 300005
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef complex<double> E;
string a,b="ZONe";
int main(){
    cin>>a;
    int ans=0;
    for(int i=0;i<9;i++){
        bool f=1;
        for(int j=i;j<i+4;j++)if(a[j]!=b[j-i])f=0;
        if(f)ans++;
    }
    cout<<ans;
    return 0;
}