#include <bits//stdc++.h>

using namespace std;

int brCif(long long n)
{
    int br=1;
    while(n>9)
    {
        br++;
        n=n/10;
    }
    return br;
}

long long stepen(int n)
{
    long long br=1;
    for(int i=0; i<n; i++)
    {
        br=br*10;
    }
    return br;
}

int mini(vector<long long> a, int n, long long sum)
{
    int br=0,d;
    int i=n-1;
    while(sum!=0)
    {
        if(sum/a[i]>0)
        {
            d=sum/a[i];
            sum=sum-d*a[i];
            br=br+d;

        }
        i--;
    }
    return br;
}

int main()
{
    int sum;
    cin>>sum;
    vector<long long> a;
    int n=brCif(sum)+1, br=0;
    for(int i=0; i<n; i++)
    {
        a.push_back(stepen(i));
        a.push_back(2*stepen(i));
        a.push_back(5*stepen(i));
        br=br+3;
    }
    sort(a.begin(),a.end());
    cout<<mini(a,br,sum);




}