#include <bits/stdc++.h>
using namespace std;
int N;
int dp[1000010];
int a[10];
int main() {
  memset(dp, 0x7f, sizeof(dp));
  dp[0] = 0;
  for (int i = 1; i < 10; i++) dp[i] = 1;
  for (int i = 10; i <= 1000000; i++) {
    memset(a, 0, sizeof(a));
    int tt = i;
    int cnt = 0;
    while (tt) {
      a[cnt] = tt % 10;
      tt /= 10;
      cnt++;
    }
    for (int j = 0; j < cnt; j++) {
      dp[i] = min(dp[i], dp[i - a[j]] + 1);
    }
  }
  while (scanf("%d", &N) != EOF) {
    printf("%d\n", dp[N]);
  }
  return 0;
}
