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

int minCoins(vector<ull> coins, int m, int V)
{
    vector<ull> table(V+1);
    table[0] = 0;

    for (int i=1; i<=V; i++)
        {
            table[i] =ULLONG_MAX;}

    for (int i=1; i<=V; i++)
    {
        for (int j=0; j<m; j++)
          if (coins[j] <= i)
          {
              int sub_res = table[i-coins[j]];
              if (sub_res != ULLONG_MAX && sub_res + 1 < table[i])
                  table[i] = sub_res + 1;
          }
    }
    return table[V];
}

int main()
{
    vector<ull> coins;
    coins.push_back(1);
    coins.push_back(2);
    coins.push_back(5);
    ull v;
    cin>>v;
    ull k=1;
    while(k<=v){
        coins.push_back(1*k);

        coins.push_back(2*k);
        coins.push_back(5*k);
        k*=10;
    }
    int m = coins.size();
    cout << minCoins(coins, m, v);
    return 0;
}