#include <iostream>
#include <cmath>
using namespace std;

long long int najveca(long long int n) {
    long long int k = 0;
    long long int rez = -1;
    bool oof = false;
    while (!oof) {
        rez = pow(10,k);
        if (rez > n) {
            k--;
            oof = true;
            break;
        } else {k++;}
    }
    rez/=10;
    int b = 1;
    if (rez * 5 > n) {
        if (rez *2 <= n) {
            b = 2;
        }
    } else {
        b = 5;
    }
    long long int konacan = rez * b;
    return konacan;
}

int main() {
    long long int n;
    cin >> n;
    long long int i = 0;
    while (n>0) {
        n-=najveca(n);
        i++;
    }
    cout << i << endl;
    return 0;
}