#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;

int64_t countDigit(int64_t v)
{
    int64_t count = 0;
    while (v >= 1) {
        v = v / 10;
        count++;
    }
    return count;
}

int64_t kvadrat(int64_t a, int64_t b)
{
    int64_t c = 1;
    while (b > 0) {
        c = c * a;
        b--;
    }
    return c;
}

int main(){
int64_t v;
cin >> v;
int64_t brojac=0;
int64_t brojCifara;


while(v>0){

brojCifara=kvadrat(10, countDigit(v) - 1);



    if (v>=brojCifara*5){
        v=v-brojCifara*5;
        brojac++;

continue;
    }

    if (v>=brojCifara*2){
        v=v-brojCifara*2;
        brojac++;

continue;
    }

    if (v>=brojCifara){
        v=v-brojCifara;
        brojac++;

    continue;
    }


}

cout << brojac;



return 0;
}