#include <bits/stdc++.h>
using namespace std;
pair<int, int> d[1000000 + 5][15];
int MD[10 * 1000000 + 5];
int md(long long x) {
  if (x >= 0 && x <= 10 * 1000000) return MD[x];
  int ans = 0;
  while (x > 0) {
    ans = max(ans, (int)(x % 10));
    x /= 10;
  }
  return ans;
}
int dig(long long x) {
  int nd = 0;
  while (x > 0) {
    nd++;
    x /= 10;
  }
  return nd;
}
pair<long long, long long> half(long long x) {
  int nd = dig(x), ns = min(6, nd);
  int i;
  long long z = 0, p = 1;
  for (i = 0; i < ns; i++) {
    z += p * (x % 10);
    p *= 10;
    x /= 10;
  }
  for (i = 0; i < ns; i++) x *= 10;
  return pair<long long, long long>(x, z);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  int i, j, z;
  for (i = 0; i <= 1000000; i++)
    for (j = 0; j <= 9; j++) d[i][j] = pair<int, int>((INT_MAX / 2 - 1), 0);
  for (j = 0; j <= 9; j++) d[0][j] = pair<int, int>(0, 0);
  for (i = 1; i <= 9; i++)
    for (j = 0; j <= 9; j++)
      if (i < j) d[i][j] = pair<int, int>(1, j - i);
  for (i = 1; i <= 1000000; i++)
    for (j = 0; j <= 9; j++) {
      if (d[i][j].first != (INT_MAX / 2 - 1)) continue;
      for (z = i; z > 0; z /= 10)
        if (d[i][j].first > 1 + d[i - z % 10][j].first ||
            (d[i][j].first == 1 + d[i - z % 10][j].first &&
             d[i][j].second < d[i - z % 10][j].second)) {
          d[i][j] = pair<int, int>(1 + d[i - z % 10][j].first,
                                   d[i - z % 10][j].second);
        }
      if (d[i][j].first > 1 + d[i - j][j].first ||
          (d[i][j].first == 1 + d[i - j][j].first &&
           d[i][j].second < d[i - j][j].second)) {
        d[i][j] = pair<int, int>(1 + d[i - j][j].first, d[i - j][j].second);
      }
    }
  for (i = 1; i <= 9; i++) MD[i] = i;
  for (; i <= 10 * 1000000; i++) MD[i] = max(MD[i / 10], i % 10);
  long long ans = 0, l, r;
  while (n > 0) {
    pair<long long, long long> cur = half(n);
    l = cur.first;
    r = cur.second;
    if (r == 0) {
      n -= md(n);
      ans++;
    } else {
      ans += d[r][md(l)].first;
      n = l - d[r][md(l)].second;
    }
  }
  cout << ans;
  return 0;
}
