#include<bits/stdc++.h>
#include<math.h>


using namespace std;

int minCoins(long long int coins[], int m,long long int V)
{
    int table[V+1];

    table[0] = 0;

    for ( long long int i=1; i<=V; i++)
        table[i] = INT_MAX;

    for ( long long 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 != INT_MAX && sub_res + 1 < table[i])
                  table[i] = sub_res + 1;
          }
    }
    return table[V];
}

int main()
{
    int k = 0,d = 1;
    long long int coins[27];
    long long int V;
    cin >> V;
    int i = 0;
    while(k < 9){
        coins[i] = d*pow(10,k);
        if (d == 1){
            d = 2;
        }else if(d == 2){
            d = 5;
        }else{
            d = 1;
            k += 1;
        }
        i++;
    }
    int m = 27;

    cout << minCoins(coins, m, V);
    return 0;
}