#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 1;
const long long INF = ~0LLU >> 1;
int rd() { return RAND_MAX == 32767 ? ((rand() << 15) ^ rand()) : rand(); }
const long long lim = 1e18;
int a[20];
long long g[10], h[10], f[20][1 << 9][9][9];
void Init(int m) {
  for (int i = 1; i <= m; i++)
    for (int v = 0; v < (1 << 9); v++)
      for (int x = 0; x < 9; x++)
        for (int y = 0; y < 9; y++) f[i][v][x][y] = lim;
  for (int v = 0; v < (1 << 9); v++)
    for (int x = 0; x < 9; x++)
      for (int y = 0; y < 9; y++)
        if (9 - x >= y) {
          for (int i = 0; i <= 9 - x - y; i++) g[i] = lim;
          g[0] = 0;
          for (int i = 0; i <= 9 - x - y; i++)
            if (g[i] != lim)
              for (int j = 1; j <= 9; j++)
                if (i + j <= 9 - x - y &&
                    (9 - x - i == j || (v >> (j - 1) & 1)))
                  g[i + j] = min(g[i + j], g[i] + 1);
          f[1][v][x][y] = g[9 - x - y];
        }
  for (int i = 2; i <= m; i++)
    for (int v = 0; v < (1 << 9); v++) {
      for (int j = 0; j < 9; j++) {
        for (int k = 0; k < 9; k++) g[k] = lim;
        g[j] = 0;
        for (int k = 0; k <= 9; k++) {
          for (int l = 0; l < 9; l++) {
            h[l] = lim;
            for (int o = 0; o < 9; o++)
              h[l] = min(h[l],
                         g[o] + f[i - 1][k == 0 ? v : v | 1 << (k - 1)][l][o]);
          }
          if (k < 9) {
            for (int l = 0; l < 9; l++) {
              g[l] = lim;
              for (int o = 1; o <= 9; o++)
                if (k + 1 == o || l == o || (v >> (o - 1) & 1)) {
                  if (l >= o)
                    g[l] = min(g[l], g[l - o] + 1);
                  else
                    g[l] = min(g[l], h[o - l - 1] + 1);
                }
            }
          }
        }
        for (int k = 0; k < 9; k++) f[i][v][k][j] = h[k];
      }
    }
}
int main() {
  long long n, res = 0;
  cin >> n;
  if (n == 1e18) {
    n--;
    res++;
  }
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (n <= 9) {
    cout << 1 << endl;
    return 0;
  }
  int m = 0;
  for (; n; n /= 10) a[++m] = n % 10;
  Init(m);
  for (int i = 0; i < 9; i++) g[i] = (i > 0);
  int v = 0;
  for (int i = m; i >= 2; i--) {
    for (int j = 0; j < a[i]; j++) {
      int vv = j > 0 ? v | 1 << (j - 1) : v;
      for (int k = 0; k < 9; k++) {
        h[k] = lim;
        for (int o = 0; o < 9; o++) h[k] = min(h[k], g[o] + f[i - 1][vv][k][o]);
      }
      for (int k = 0; k < 9; k++) {
        g[k] = lim;
        for (int o = 1; o <= 9; o++)
          if (j + 1 == o || k == o || (v >> (o - 1) & 1)) {
            if (k >= o)
              g[k] = min(g[k], g[k - o] + 1);
            else
              g[k] = min(g[k], h[o - k - 1] + 1);
          }
      }
    }
    if (a[i] > 0) v |= 1 << (a[i] - 1);
  }
  if (a[1] <= 8)
    res += g[a[1]];
  else {
    long long cnt = lim;
    for (int i = 1; i <= m; i++)
      if (a[i] > 0) cnt = min(cnt, g[9 - a[i]] + 1);
    res += cnt;
  }
  cout << res << endl;
  return 0;
}
