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

unsigned long long power[19];

int getDigits(unsigned long long n) {
    int k = 0;

    while (n != 0) {
        n /= 10;
        k++;
    }

    return k;
}

int solve(unsigned long long n) {
    int digits = getDigits(n);
    int k = 0;

    while (n > 0) {
        unsigned long long d = power[digits - 1];
        unsigned long long sub;
        if (5 * d <= n) {
            sub = 5 * d;
            n -= sub;
            k++;
        } else if (2 * d <= n) {
            sub = 2 * d;
            n -= 2 * d;
            k++;
        } else if (d <= n) {
            sub = 1 * d;
            n -= d;
            k++;
        }
        digits = getDigits(n);
    }

    return k;
}

int main() {
    ios_base::sync_with_stdio(false);

    unsigned long long n;
    cin >> n;

    for (int i = 0; i < 19; i++) {
        if (i == 0)
            power[i] = 1;
        else
            power[i] = power[i - 1] * 10;
    }

    cout << solve(n);

    return 0;
}