#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    long long int br;

    cin >> br;
    long long int x = br;
    int t = 0;
    int brojac = 0;

    while(x != 0){
        x = x / 10;
        t++;
    }

    while(br != 0){
    if(5*pow(10, t-1) <= br){
        br = br - 5*pow(10, t-1);
        brojac++;
    } else if(2*pow(10, t-1) <= br){
        br = br - 2*pow(10, t-1);
        brojac++;
    } else if(pow(10, t-1) <= br){
        br = br - 1*pow(10, t-1);
        brojac++;
    } else {
        t--;
    }
    }

    cout << brojac;

    return 0;
}