#include <bits/stdc++.h>

using namespace std;

vector<long long> pare;

int main()
{
    long long v;
    cin >> v;
    int novc = 0;
    int u = 0;

    for(int i = 0; i < 19; i++)
    {
        pare.push_back(1 * pow(10, i));
        novc++;
        if((pare[novc - 1] % 10 != 0) && (pare[novc - 1] / 10 != 0))
        pare[novc - 1]++;
        pare.push_back(2 * pow(10, i));
        novc++;
        if((pare[novc - 1] % 10 != 0) && (pare[novc - 1] / 10 != 0))
        pare[novc - 1]++;
        pare.push_back(5 * pow(10, i));
        novc++;
        if((pare[novc - 1] % 10 != 0) && (pare[novc - 1] / 10 != 0))
        pare[novc - 1]++;
    }

    for(int i = novc - 1; i >= 0; i--)
    {
        while(v / pare[i] > 0)
        {
            v -= pare[i];
            u++;
        }
    }

    cout << u << '\n';
    return 0;
}