#include <iostream>

using namespace std;
int granica(long long V){
    int br=1;
    while(10*br<=V)
        br*=10;
    if(5*br<=V)
        return br*5;
    else if(2*br<=V)
        return 2*br;
    return br;
}

int brojNovcanica(long long V){
    int br=0;
    while(V!=0){
        V-=granica(V);
        br++;
    }
    return br;
}
int main()
{

    long long V;
    cin>>V;
    cout << brojNovcanica(V) << endl;
    return 0;
}