#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define srt(v) sort(v.begin(),v.end())
#define srtg(v,int) sort(v.begin(),v.end(),greater<int>())
#define lb(a,v) lower_bound(v.begin(),v.end(),a)
#define ub(a,v) upper_bound(v.begin(),v.end(),a)
#define fnd(a,v) find(v.begin(),v.end(),a)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef string str;

int main()
{
    ll v;
    cin>>v;
    vector<int> niz;
    while(v>0){
        niz.pb(v%10);
        v/=10;
    }
    ll res=0;
    vector<int> nov={5,2,1};
    for(int i=0;i<niz.size();i++){
        for(int j=0;j<3;j++){
            while(niz[i]>=nov[j]){
                niz[i]-=nov[j];
                res++;
            }
        }
    }
    cout<<res;
    return 0;
}