#include <iostream>
#include <math.h>
using namespace std;

int foo(int d[], int n, int V) {
  #define razumanbroj 1000
  int bills[razumanbroj];
  int numofbills = 0;
  for (int i = 0; i < n; i++) {
    int k = 0;
    while (d[i] * pow(10, k) < V) {
      bills[numofbills++] = d[i] * pow(10, k++);
    }
  }

  int memo[V + 1];
  memo[0] = 0;
  for (int i = 1; i <= V; i++) memo[i] = INT_MAX;

  cout << endl;

  for (int i = 1; i <= V; i++) {
    for (int j = 0; j < numofbills; j++) {
      if (bills[j] <= i) {
        int temp = memo[i - bills[j]];
        if (temp + 1 < memo[i]) memo[i] = temp + 1;
      }
    }
  }

  #undef razumanbroj
  return memo[V];
}

int main(int argc, char const* argv[]) {
  int V, d[3] = {1, 2, 5};
  cin >> V;

  cout << foo(d, sizeof(d) / sizeof(int), V) << endl;

  return 0;
}