#include<bits/stdc++.h>
#include<math.h>
#define ull unsigned long long
using namespace std;

int minCoins( int V)
{
    vector<ull> table(V+1,ULLONG_MAX);
    table[0] = 0;
    int j=1,k=1;
    for (int i=1; i<=V; i++)
    {
        if(k*10==i)k*=10;
        if(i<pow(10,18)&&2*k==i)j=2*k;
        if(i<pow(10,18)&&5*k==i)j=5*k;

              int sub_res = table[i-j];
              if (sub_res != ULLONG_MAX && sub_res + 1 < table[i])
                  table[i] = sub_res + 1;

    }
    return table[V];
}

int main()
{
    ull v;
    cin>>v;
    cout << minCoins(  v);
    return 0;
}