#include <iostream>
using namespace std;

int main () {
    int V, L[];
    cin >> V;
    int Vt = V;

    while (Vt != 0) {
        int i;
        L[i] = Vt % 10;
        Vt / 10;
        i++;
    }

    while (L != 1) {
        int j;
        Vt = V;
        if (L[i] => 5) Vt -= 5 * 10^(L-1) && j++;
        else if (L[i] => 2 && L[i] < 5) Vt -= 2 * 10^(L-1) && j++;
    }

    cout << j;
}