#include <bits/stdc++.h>
#pragma GCC optimize(3)
namespace orz {
inline void read(int &x) { scanf("%d", &x); }
inline void read(unsigned int &x) { scanf("%u", &x); }
inline void read(long long &x) { scanf("%I64d", &x); }
inline void read(unsigned long long &x) { scanf("%I64u", &x); }
inline void read(double &x) { scanf("%lf", &x); }
inline void read(long double &x) {
  double tmp;
  read(tmp);
  x = tmp;
}
inline void read(char &x) { x = getchar(); }
inline void read(char *x) { scanf("%s", x); }
template <class T>
inline void read(T *a, int n) {
  for (int i = (0); i < (n); ++i) read(a[i]);
}
template <class T1, class T2>
inline void read(T1 &a, T2 &b) {
  read(a);
  read(b);
}
template <class T1, class T2, class T3>
inline void read(T1 &a, T2 &b, T3 &c) {
  read(a);
  read(b);
  read(c);
}
template <class T1, class T2, class T3, class T4>
inline void read(T1 &a, T2 &b, T3 &c, T4 &d) {
  read(a);
  read(b);
  read(c);
  read(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline void read(T1 &a, T2 &b, T3 &c, T4 &d, T5 &e) {
  read(a);
  read(b);
  read(c);
  read(d);
  read(e);
}
inline void write(const int x) { printf("%d", x); }
inline void write(const unsigned int x) { printf("%u", x); }
inline void write(const long long x) { printf("%I64d", x); }
inline void write(const unsigned long long x) { printf("%I64u", x); }
inline void write(const double x) { printf("%.10lf", x); }
inline void write(const long double x) { printf("%.10lf", (double)x); }
inline void write(const char x) { putchar(x); }
inline void write(const char *x) { printf("%s", x); }
template <class T>
inline void writes(T x) {
  write(x);
  putchar(' ');
}
template <class T1, class T2>
inline void writes(T1 a, T2 b) {
  writes(a);
  writes(b);
}
template <class T1, class T2, class T3>
inline void writes(T1 a, T2 b, T3 c) {
  writes(a);
  writes(b);
  writes(c);
}
template <class T1, class T2, class T3, class T4>
inline void writes(T1 a, T2 b, T3 c, T4 d) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline void writes(T1 a, T2 b, T3 c, T4 d, T5 e) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
  writes(e);
}
template <class T1, class T2>
inline void writesln(T1 a, T2 b) {
  writes(a);
  writes(b);
  putchar('\n');
}
template <class T1, class T2, class T3>
inline void writesln(T1 a, T2 b, T3 c) {
  writes(a);
  writes(b);
  writes(c);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4>
inline void writesln(T1 a, T2 b, T3 c, T4 d) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4, class T5>
inline void writesln(T1 a, T2 b, T3 c, T4 d, T5 e) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
  writes(e);
  putchar('\n');
}
template <class T1, class T2>
inline void writeln(T1 a, T2 b) {
  write(a);
  write(b);
  putchar('\n');
}
template <class T1, class T2, class T3>
inline void writeln(T1 a, T2 b, T3 c) {
  write(a);
  write(b);
  write(c);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4>
inline void writeln(T1 a, T2 b, T3 c, T4 d) {
  write(a);
  write(b);
  write(c);
  write(d);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4, class T5>
inline void writeln(T1 a, T2 b, T3 c, T4 d, T5 e) {
  write(a);
  write(b);
  write(c);
  write(d);
  write(e);
  putchar('\n');
}
template <class T1, class T2>
inline void write(T1 a, T2 b) {
  write(a);
  write(b);
}
template <class T1, class T2, class T3>
inline void write(T1 a, T2 b, T3 c) {
  write(a);
  write(b);
  write(c);
}
template <class T1, class T2, class T3, class T4>
inline void write(T1 a, T2 b, T3 c, T4 d) {
  write(a);
  write(b);
  write(c);
  write(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline void write(T1 a, T2 b, T3 c, T4 d, T5 e) {
  write(a);
  write(b);
  write(c);
  write(d);
  write(e);
}
template <class T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
template <class T>
inline void writeln(T *a, int n) {
  for (int i = (0); i < (n); ++i) write(a[i]);
  putchar('\n');
}
template <class T>
inline void writesln(T *a, int n) {
  for (int i = (0); i < (n); ++i) writes(a[i]);
  putchar('\n');
}
template <class T>
inline void writelnln(T *a, int n) {
  for (int i = (0); i < (n); ++i) writeln(a[i]);
}
}  // namespace orz
using namespace orz;
std::map<std::pair<unsigned long long, int>,
         std::pair<unsigned long long, int> >
    res;
inline std::pair<unsigned long long, int> dfs(unsigned long long x, int m) {
  std::map<std::pair<unsigned long long, int>,
           std::pair<unsigned long long, int> >::iterator it =
      res.find(std::pair<int, int>(x, m));
  if (it != res.end()) return it->second;
  std::pair<unsigned long long, int> &ans = res[std::pair<int, int>(x, m)];
  if (x) {
    if (x < 10)
      ans = std::pair<unsigned long long, int>(1, std::max((int)x, m) - (int)x);
    else {
      unsigned long long c = 1ull;
      while (c * 10ull <= x) c *= 10ull;
      int fir = x / c;
      ans.first = 0;
      unsigned long long xx = x % c;
      for (int i = (fir); i >= (1); --i) {
        int mm = std::max(m, i);
        std::pair<unsigned long long, int> tmp = dfs(xx, mm);
        ans.first += tmp.first;
        if (tmp.second)
          xx = c - (unsigned long long)tmp.second;
        else {
          ++ans.first;
          xx = c - (unsigned long long)mm;
        }
      }
      std::pair<unsigned long long, int> tmp = dfs(xx, m);
      ans.first += tmp.first;
      ans.second = tmp.second;
    }
  } else
    ans = std::pair<unsigned long long, int>(0, 0);
  return ans;
}
int main() {
  unsigned long long n;
  read(n);
  writeln(dfs(n, 0).first);
  return 0;
}

### Prompt

Develop a solution in CPP to the problem described below:

Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. 

The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows: 

"May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!"

Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero.

Input

The single line contains the magic integer n, 0 ≤ n.

  * to get 20 points, you need to solve the problem with constraints: n ≤ 106 (subproblem C1); 
  * to get 40 points, you need to solve the problem with constraints: n ≤ 1012 (subproblems C1+C2); 
  * to get 100 points, you need to solve the problem with constraints: n ≤ 1018 (subproblems C1+C2+C3). 

Output

Print a single integer — the minimum number of subtractions that turns the magic number to a zero.

Examples

Input

24


Output

5

Note

In the first test sample the minimum number of operations can be reached by the following sequence of subtractions: 

24 → 20 → 18 → 10 → 9 → 0

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize(3)
namespace orz {
inline void read(int &x) { scanf("%d", &x); }
inline void read(unsigned int &x) { scanf("%u", &x); }
inline void read(long long &x) { scanf("%I64d", &x); }
inline void read(unsigned long long &x) { scanf("%I64u", &x); }
inline void read(double &x) { scanf("%lf", &x); }
inline void read(long double &x) {
  double tmp;
  read(tmp);
  x = tmp;
}
inline void read(char &x) { x = getchar(); }
inline void read(char *x) { scanf("%s", x); }
template <class T>
inline void read(T *a, int n) {
  for (int i = (0); i < (n); ++i) read(a[i]);
}
template <class T1, class T2>
inline void read(T1 &a, T2 &b) {
  read(a);
  read(b);
}
template <class T1, class T2, class T3>
inline void read(T1 &a, T2 &b, T3 &c) {
  read(a);
  read(b);
  read(c);
}
template <class T1, class T2, class T3, class T4>
inline void read(T1 &a, T2 &b, T3 &c, T4 &d) {
  read(a);
  read(b);
  read(c);
  read(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline void read(T1 &a, T2 &b, T3 &c, T4 &d, T5 &e) {
  read(a);
  read(b);
  read(c);
  read(d);
  read(e);
}
inline void write(const int x) { printf("%d", x); }
inline void write(const unsigned int x) { printf("%u", x); }
inline void write(const long long x) { printf("%I64d", x); }
inline void write(const unsigned long long x) { printf("%I64u", x); }
inline void write(const double x) { printf("%.10lf", x); }
inline void write(const long double x) { printf("%.10lf", (double)x); }
inline void write(const char x) { putchar(x); }
inline void write(const char *x) { printf("%s", x); }
template <class T>
inline void writes(T x) {
  write(x);
  putchar(' ');
}
template <class T1, class T2>
inline void writes(T1 a, T2 b) {
  writes(a);
  writes(b);
}
template <class T1, class T2, class T3>
inline void writes(T1 a, T2 b, T3 c) {
  writes(a);
  writes(b);
  writes(c);
}
template <class T1, class T2, class T3, class T4>
inline void writes(T1 a, T2 b, T3 c, T4 d) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline void writes(T1 a, T2 b, T3 c, T4 d, T5 e) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
  writes(e);
}
template <class T1, class T2>
inline void writesln(T1 a, T2 b) {
  writes(a);
  writes(b);
  putchar('\n');
}
template <class T1, class T2, class T3>
inline void writesln(T1 a, T2 b, T3 c) {
  writes(a);
  writes(b);
  writes(c);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4>
inline void writesln(T1 a, T2 b, T3 c, T4 d) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4, class T5>
inline void writesln(T1 a, T2 b, T3 c, T4 d, T5 e) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
  writes(e);
  putchar('\n');
}
template <class T1, class T2>
inline void writeln(T1 a, T2 b) {
  write(a);
  write(b);
  putchar('\n');
}
template <class T1, class T2, class T3>
inline void writeln(T1 a, T2 b, T3 c) {
  write(a);
  write(b);
  write(c);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4>
inline void writeln(T1 a, T2 b, T3 c, T4 d) {
  write(a);
  write(b);
  write(c);
  write(d);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4, class T5>
inline void writeln(T1 a, T2 b, T3 c, T4 d, T5 e) {
  write(a);
  write(b);
  write(c);
  write(d);
  write(e);
  putchar('\n');
}
template <class T1, class T2>
inline void write(T1 a, T2 b) {
  write(a);
  write(b);
}
template <class T1, class T2, class T3>
inline void write(T1 a, T2 b, T3 c) {
  write(a);
  write(b);
  write(c);
}
template <class T1, class T2, class T3, class T4>
inline void write(T1 a, T2 b, T3 c, T4 d) {
  write(a);
  write(b);
  write(c);
  write(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline void write(T1 a, T2 b, T3 c, T4 d, T5 e) {
  write(a);
  write(b);
  write(c);
  write(d);
  write(e);
}
template <class T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
template <class T>
inline void writeln(T *a, int n) {
  for (int i = (0); i < (n); ++i) write(a[i]);
  putchar('\n');
}
template <class T>
inline void writesln(T *a, int n) {
  for (int i = (0); i < (n); ++i) writes(a[i]);
  putchar('\n');
}
template <class T>
inline void writelnln(T *a, int n) {
  for (int i = (0); i < (n); ++i) writeln(a[i]);
}
}  // namespace orz
using namespace orz;
std::map<std::pair<unsigned long long, int>,
         std::pair<unsigned long long, int> >
    res;
inline std::pair<unsigned long long, int> dfs(unsigned long long x, int m) {
  std::map<std::pair<unsigned long long, int>,
           std::pair<unsigned long long, int> >::iterator it =
      res.find(std::pair<int, int>(x, m));
  if (it != res.end()) return it->second;
  std::pair<unsigned long long, int> &ans = res[std::pair<int, int>(x, m)];
  if (x) {
    if (x < 10)
      ans = std::pair<unsigned long long, int>(1, std::max((int)x, m) - (int)x);
    else {
      unsigned long long c = 1ull;
      while (c * 10ull <= x) c *= 10ull;
      int fir = x / c;
      ans.first = 0;
      unsigned long long xx = x % c;
      for (int i = (fir); i >= (1); --i) {
        int mm = std::max(m, i);
        std::pair<unsigned long long, int> tmp = dfs(xx, mm);
        ans.first += tmp.first;
        if (tmp.second)
          xx = c - (unsigned long long)tmp.second;
        else {
          ++ans.first;
          xx = c - (unsigned long long)mm;
        }
      }
      std::pair<unsigned long long, int> tmp = dfs(xx, m);
      ans.first += tmp.first;
      ans.second = tmp.second;
    }
  } else
    ans = std::pair<unsigned long long, int>(0, 0);
  return ans;
}
int main() {
  unsigned long long n;
  read(n);
  writeln(dfs(n, 0).first);
  return 0;
}

```