#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    long int V,br_nov,naj_nov,d,k,V_medj;
    scanf("%ld", &V);
    while(V != 0){
        V_medj = V;
        k = 0;
        while(V_medj >= 10){
            V_medj /= 10;
            k++;
        }
        if(V_medj == 1){
            d = 1;
        }else if(V_medj <= 4){
            d = 2;
        }else{
            d = 5;
        }
        naj_nov = (long int)(d * pow(10, k));
        while(naj_nov <= V){
            V -= naj_nov;
            br_nov ++;
        }
    }
    printf("%ld", br_nov);

    return 0;
}