//cop code
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define hutao_my_wife ios_base::sync_with_stdio(0);
#define forcalors_so_cute cin.tie(0);
#define ll long long
#define int ll //這個int單純是因為debug時懶得找溢位的程式碼
#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define bug(A) cout<<A<<" hi\n";
using namespace std;
const int M = 200005;
ll dp[20][10][10];
ll to[20][10][10];
int maxdigital(ll x){
ll ans = 0;
while(x){
ans = max(ans,x%10);
x/=10;
}
return ans;
}
int numi(ll x){
x/=10;
int ans = 0;
while(x%10 == 9){
ans++;
x/=10;
}
return ans;
}
void solve(){
ll n;
cin>>n;
ll ans = 0;
while(n>0){
int i = numi(n);
int k = maxdigital(n - n%(ll)pow(10,i+1));
int j = n%10;
ans += dp[i][j][k];
n -= (ll)pow(10,i+1);
n = n - n%10 + to[i][j][k];
}
cout<<ans<<'\n';
}
signed main()
{
hutao_my_wife forcalors_so_cute
int t = 1;
memset(dp,0,sizeof(dp));
for(int i = 0; i <= 18; i++){
for(int k = 0; k < 10; k++){
for(int j = 0; j < 10; j++){
if(i+j+k == 0){
to[i][j][k] = 0;
continue;
}
if(i+k == 0){
dp[i][j][k]=1,to[i][j][k]=0;continue;
}
if(i == 0){
if(j < k)dp[i][j][k] = 1,to[i][j][k]=(10+j-k)%10;
else dp[i][j][k] = 2,to[i][j][k] = (10-k)%10;
continue;
}
int last = j;
for(int l = 9; l >= 0; l--){
dp[i][j][k] += dp[i-1][last][max(k,l)];
last = to[i-1][last][max(k,l)];
}
to[i][j][k] = last;
}
}
}
while(t--){
solve();
}
}
Ly9jb3AgY29kZQojcHJhZ21hIEdDQyBvcHRpbWl6ZSgiT2Zhc3QiKQojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBodXRhb19teV93aWZlIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiNkZWZpbmUgZm9yY2Fsb3JzX3NvX2N1dGUgY2luLnRpZSgwKTsKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBpbnQgbGwgLy/pgJnlgItpbnTllq7ntJTmmK/lm6DngrpkZWJ1Z+aZguaHtuW+l+aJvua6ouS9jeeahOeoi+W8j+eivAojZGVmaW5lIHBpaSBwYWlyPGludCxpbnQ+CiNkZWZpbmUgZmYgZmlyc3QKI2RlZmluZSBzcyBzZWNvbmQKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBlYiBlbXBsYWNlX2JhY2sKI2RlZmluZSBidWcoQSkgY291dDw8QTw8IiBoaVxuIjsKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBNID0gMjAwMDA1OwpsbCBkcFsyMF1bMTBdWzEwXTsKbGwgdG9bMjBdWzEwXVsxMF07CmludCBtYXhkaWdpdGFsKGxsIHgpewogICAgbGwgYW5zID0gMDsKICAgIHdoaWxlKHgpewogICAgICAgIGFucyA9IG1heChhbnMseCUxMCk7CiAgICAgICAgeC89MTA7CiAgICB9CiAgICByZXR1cm4gYW5zOwp9CmludCBudW1pKGxsIHgpewogICAgeC89MTA7CiAgICBpbnQgYW5zID0gMDsKICAgIHdoaWxlKHglMTAgPT0gOSl7CiAgICAgICAgYW5zKys7CiAgICAgICAgeC89MTA7CiAgICB9CiAgICByZXR1cm4gYW5zOwp9CnZvaWQgc29sdmUoKXsKICAgIGxsIG47CiAgICBjaW4+Pm47CiAgICBsbCBhbnMgPSAwOwogICAgd2hpbGUobj4wKXsKICAgICAgICBpbnQgaSA9IG51bWkobik7CiAgICAgICAgaW50IGsgPSBtYXhkaWdpdGFsKG4gLSBuJShsbClwb3coMTAsaSsxKSk7CiAgICAgICAgaW50IGogPSBuJTEwOwogICAgICAgIGFucyArPSBkcFtpXVtqXVtrXTsKICAgICAgICBuIC09IChsbClwb3coMTAsaSsxKTsKICAgICAgICBuID0gbiAtIG4lMTAgKyB0b1tpXVtqXVtrXTsKICAgIH0KICAgIGNvdXQ8PGFuczw8J1xuJzsKCn0Kc2lnbmVkIG1haW4oKQp7CiAgICBodXRhb19teV93aWZlIGZvcmNhbG9yc19zb19jdXRlCgogICAgaW50IHQgPSAxOwogICAgbWVtc2V0KGRwLDAsc2l6ZW9mKGRwKSk7CiAgICBmb3IoaW50IGkgPSAwOyBpIDw9IDE4OyBpKyspewogICAgICAgIGZvcihpbnQgayA9IDA7IGsgPCAxMDsgaysrKXsKICAgICAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IDEwOyBqKyspewogICAgICAgICAgICAgICAgaWYoaStqK2sgPT0gMCl7CiAgICAgICAgICAgICAgICAgICAgdG9baV1bal1ba10gPSAwOwogICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYoaStrID09IDApewogICAgICAgICAgICAgICAgICAgICAgICBkcFtpXVtqXVtrXT0xLHRvW2ldW2pdW2tdPTA7Y29udGludWU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZihpID09IDApewogICAgICAgICAgICAgICAgICAgIGlmKGogPCBrKWRwW2ldW2pdW2tdID0gMSx0b1tpXVtqXVtrXT0oMTArai1rKSUxMDsKICAgICAgICAgICAgICAgICAgICBlbHNlIGRwW2ldW2pdW2tdID0gMix0b1tpXVtqXVtrXSA9ICgxMC1rKSUxMDsKICAgICAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGludCBsYXN0ID0gajsKICAgICAgICAgICAgICAgIGZvcihpbnQgbCA9IDk7IGwgPj0gMDsgbC0tKXsKICAgICAgICAgICAgICAgICAgICBkcFtpXVtqXVtrXSArPSBkcFtpLTFdW2xhc3RdW21heChrLGwpXTsKICAgICAgICAgICAgICAgICAgICBsYXN0ID0gdG9baS0xXVtsYXN0XVttYXgoayxsKV07CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB0b1tpXVtqXVtrXSA9IGxhc3Q7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICB3aGlsZSh0LS0pewogICAgICAgIHNvbHZlKCk7CiAgICB9Cn0K