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

int main()
{
    long long v, br = 0, a = 51, k, i = 0;
    long long novcanice[54];
    cin >> v;
    for(k = 0; k < 18; k++)
    {
        novcanice[i] = pow(10, k);
        i++;
        novcanice[i] = 2*pow(10, k);
        i++;
        novcanice[i] = 5*pow(10, k);
        i++;
    }
    while(v > 0)
    {
        if(novcanice[a] <= v)
        {
            v -= novcanice[a];
            br++;
        }
        else a--;
    }
    cout << br;
    return 0;
}