#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MOD = 1e9+7;
const ll INF = 1e18;
vector<ll>a;

void gen(){
    a.push_back(1LL);
    a.push_back(2LL);
    a.push_back(5LL);

    ll s=1LL;
    while(true){
        if(INF/10LL>=s){
            s*=10LL;
            a.push_back(s);
            if(INF/2LL>=s){
                a.push_back(2LL*s);
            }
            if(INF/5LL>=s){
                a.push_back(5LL*s);
            }
        }else {
            break;
        }
    }
    sort(a.begin(),a.end());
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    gen();

    ll n,ans=0;
    cin>>n;

    while(n>0){
        for(int i=(int)a.size()-1;i>=0;i--){
            if(n>=a[i]){
                ans++;
                n-=a[i];
                break;
            }
        }
    }

    cout<<ans;
    return 0;
}