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 ≤ 10^6 (subproblem C1);  to get 40 points, you need to solve the problem with constraints: n ≤ 10^12 (subproblems C1+C2);  to get 100 points, you need to solve the problem with constraints: n ≤ 10^18 (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

Difficulty: EASY
Tags: Dynamic programming
Skill types: Dynamic programming

Starter code:

Solutions:
n = input()
num = int(n)
count = 1
if num == 0:
	print(0)
else:
	while num >= 10:
		num -= int(max(list(n)))
		count += 1
		n = str(num)
	print(count)


n = int(input())
ans = 0
while n:
	maxd = 0
	tmp = n
	while tmp:
		maxd = max(maxd, tmp % 10)
		tmp //= 10
	n -= maxd
	ans += 1
print(ans)


num = int(input())
count = 0
while num > 0:
	num -= int(max(list(str(num))))
	count += 1
print(count)


def get_subs(n):
	count = 0
	while n != '0':
		digits = [int(i) for i in n]
		max_digit = max(digits)
		n = int(n) - max_digit
		n = str(n)
		count += 1
	return count
n = input()
print(get_subs(n))


n = int(input())
steps = 0
while n:
	n -= int(max(str(n)))
	steps += 1
print(steps)


import functools
Maxn = 10000005

@functools.lru_cache(10000)
def dp(x, y):
	now = (x, y)
	if x < 10:
		first = 1 if x or y else 0
		return (first, x - max(x, y))
	mod = 1
	while mod <= x // 10:
		mod *= 10
	maxDig = x // mod
	part1 = dp(x % mod, max(maxDig, y))
	part2 = dp(x - x % mod + part1[1], y)
	return (part1[0] + part2[0], part2[1])

def solve():
	n = int(input())
	Ans = dp(n, 0)[0]
	print(Ans)
solve()


n = int(input())

def getMaxDigit(i):
	s = str(i)
	x = int(s[0])
	for c in s:
		x = max(int(c), x)
		if x == 9:
			return x
	return x
count = 0
while n != 0:
	n -= getMaxDigit(n)
	count += 1
print(count)


n = input()
cnt = 0
while int(n) > 0:
	n = str(int(n) - int(max(n)))
	cnt += 1
print(cnt)


def maxd(a):
	maxv = 0
	while a:
		d = a % 10
		maxv = max(maxv, d)
		a = a // 10
	return maxv
n = int(input())
i = 0
while n:
	md = maxd(n)
	n -= md
	i += 1
print(i)


(n, k) = (int(input()), 0)
while n:
	n = n - int(max(str(n)))
	k += 1
print(k)


n = int(input())
count = 0
while n > 0:
	n -= int(max(str(n)))
	count += 1
print(count)


n = int(input(''))

def maxdig(n):
	s = -1
	while n:
		s = max(s, n % 10)
		n = n // 10
	return s
sol = 0
while n:
	sol += 1
	n -= maxdig(n)
print(sol)


import random
import math
import itertools
liczba = int(input())
wynik = 0
while liczba != 0:
	maks = 0
	for x in str(liczba):
		maks = max(maks, int(x))
	liczba -= maks
	wynik += 1
print(wynik)


n = int(input())
ans = 0
while n > 0:
	i = n
	s = 0
	while i > 0:
		s = max(s, i % 10)
		i = i // 10
	ans += 1
	n -= s
print(ans)


n = int(input())
f = n
s = 1
while n > 9:
	n -= max(map(int, str(n)))
	s += 1
if f == 0:
	print(0)
else:
	print(s)


n = int(input())
count = 0
while n != 0:
	calc_c = n
	max = calc_c % 10
	calc_c = int(calc_c / 10)
	while calc_c != 0:
		temp = calc_c % 10
		if temp > max:
			max = temp
		calc_c = int(calc_c / 10)
	n -= max
	count += 1
print(count)


import math
import sys

def solve(n):
	counter = 0
	while n != 0:
		num = str(n)
		num = set(num)
		max_digit = 0
		for x in num:
			if int(x) > max_digit:
				max_digit = int(x)
		n -= max_digit
		counter += 1
	return counter

def s():
	n = int(input())
	print(solve(n))
s()


n = list(input())
if len(n) == 1 and n[0] == '0':
	print(0)
	exit()
c = 0
while True:
	if len(n) == 1:
		break
	else:
		s = int(max(n))
		m = int(int(''.join(n)) - s)
		n = list(str(m))
		c += 1
print(c + 1)


from collections import defaultdict
n = int(input())
d = defaultdict()

def helper(n):
	temp = float('inf')
	if n == 0:
		return 0
	if n < 0:
		return float('inf')
	if n in d.keys():
		return d[n]
	for i in str(n):
		if i != '0':
			temp = min(temp, 1 + helper(n - int(i)))
	d[n] = temp
	return temp
count = 0
while n > 0:
	count += 1
	n -= max([int(i) for i in str(n)])
if n == 0:
	print(count)
else:
	print(count + 1)


import random
import math
import itertools

def main():
	n = int(input())
	if n == 0:
		print(0)
	elif n < 10:
		print(1)
	else:
		dp = [0] * (n + 1)
		dp[1:10] = [1] * 9
		m = 10
		while m != n + 1:
			s = 0
			p = m
			while m != 0:
				s = max(s, m % 10)
				m = m // 10
			dp[p] = dp[p - s] + 1
			m = p + 1
		print(dp[n])
main()


n = int(input())
c = 0
while n > 0:
	p = str(n)
	q = max(p)
	n -= int(q)
	c += 1
print(c)


n = int(input())
cnt = 0
while n > 0:
	mx = -100
	for i in str(n):
		mx = max(mx, int(i))
	n -= mx
	mx = -100
	cnt += 1
print(cnt)


n = input()
count = 0
l = list(map(int, n))
while int(n) > 0:
	l = list(map(int, n))
	m = max(l)
	n = int(n) - m
	count += 1
	n = str(n)
print(count)


import sys
sys.setrecursionlimit(15000000)

def solve():
	n = int(input())
	mem = [1000000] * (n + 1)
	mem[0] = 0
	for i in range(1, n + 1):
		ncopy = i
		while ncopy > 0:
			last = ncopy % 10
			ncopy //= 10
			if last != 0 and i - last >= 0:
				mem[i] = min(mem[i], 1 + mem[i - last])
	print(mem[n])
if sys.hexversion == 50594544:
	sys.stdin = open('test.txt')
solve()


n = int(input())

def ispres(num):
	dig = 0
	m = num
	while m > 0:
		d = m % 10
		dig = max(dig, d)
		m = m // 10
	return dig
dp = [999999 for _ in range(n + 1)]
dp[n - ispres(n)] = 1
if n == 0:
	print(0)
	exit(0)
for i in range(n, -1, -1):
	k = ispres(i)
	if i - k >= 0:
		dp[i - k] = min(dp[i - k], dp[i] + 1)
if dp[0] == 999999:
	print(0)
	exit(0)
print(dp[0])


a = int(input())
b = a
countt = 0
while b > 0:
	l = []
	countt += 1
	while a > 0:
		l.append(a % 10)
		a = a // 10
	l = sorted(l)
	b = b - l[-1]
	a = b
print(countt)


n = int(input())
s = 0
while n != 0:
	n -= max([int(c) for c in str(n)])
	s += 1
print(s)


c = '0123456789'
F = {c[a] + c[b]: (c[10 - a + b], 1) if a > b else (c[10 - a], 2) for a in range(1, 10) for b in range(10)}
for b in range(1, 10):
	F['0' + c[b]] = ('0', 1)
F['00'] = ('0', 0)

def f(x):
	global F
	if x in F:
		return F[x]
	(a, b, y, s) = (int(x[0]), int(x[1]), x[2:], 0)
	for i in range(b, a, -1):
		(y, d) = f(c[i] + y)
		s += d
	for i in range(min(a, b) + 1):
		(y, d) = f(x[0] + y)
		s += d
	F[x] = ('9' + y, s)
	return F[x]
print(f('0' + input())[1])


n = int(input())
count = 0
while n > 0:
	s1 = str(n)
	l1 = []
	for i in range(len(s1)):
		l1.append(int(s1[i]))
	n -= max(l1)
	count += 1
print(count)


x = int(input())
place = 10
bigdig = 0
ans = 0
while x:
	string = str(x)
	bigdig = 0
	for digit in string:
		if int(digit) > bigdig:
			bigdig = int(digit)
	x = x - bigdig
	ans += 1
print(ans)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def cal(a, b, ans, d):
	if (a < 1 or b < 1) or (a < 2 and b < 2):
		return ans
	if d.get((a, b), -1) != -1:
		return d[a, b]
	d[a, b] = max(cal(a + 1, b - 2, ans + 1, d), cal(a - 2, b + 1, ans + 1, d))
	return d[a, b]

def main():
	try:
		n = I()
		ans1 = 0
		while n > 0:
			t = n
			ans = 0
			while t > 0:
				ans = max(t % 10, ans)
				t //= 10
			n -= ans
			ans1 += 1
		print(ans1)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


n = int(input())
count = 0
while n > 0:
	n_arr = list(str(n))
	n_arr_sorted = sorted(n_arr)
	n = n - int(n_arr_sorted[len(n_arr_sorted) - 1])
	count += 1
print(count)


a = int(input())
k = 0
while a > 0:
	a -= max([int(c) for c in str(a)])
	k += 1
print(k)


num = int(input())
c = 0
while num != 0:
	k = list(str(num))
	d = int(max(k))
	num -= d
	c += 1
print(c)


n = int(input())
c = 0
while n:
	t = list(map(int, list(str(n))))
	n -= max(t)
	c += 1
print(c)


a = input()
c = 0
while True:
	if a == '0':
		break
	b = 0
	for x in a:
		if int(x) > b:
			b = int(x)
	a = str(int(a) - b)
	c += 1
print(c)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = ii()
c = 0
while n > 0:
	n -= int(max(list(str(n))))
	c += 1
print(c)


num = int(input())
counter = 0
while num != 0:
	num -= max([int(i) for i in str(num)])
	counter += 1
print(counter)


import math
q = 1
for _ in range(q):
	n = int(input())
	ans = 0
	while n > 0:
		ans += 1
		k = n
		maxx = 0
		while k > 0:
			x = k % 10
			maxx = max(x, maxx)
			k //= 10
		n -= maxx
	print(ans)


n = int(input())

def Digits(n):
	largest = 0
	while n:
		r = n % 10
		largest = max(r, largest)
		n = n // 10
	return largest

def c1(n):
	if n == 0:
		print('0')
	else:
		l = n
		t = 0
		while l != 0:
			t = t + 1
			l = l - Digits(l)
			if l == 0:
				print(t)
c1(n)


def dsolve(m):
	memo = {0: 0}

	def solve(k):
		l = len(str(k))
		if k in memo.keys():
			return memo[k]
		elif len(str(k)) == 1:
			memo[k] = 1
			return 1
		else:
			p = 1 + min([solve(k - int(c)) for c in str(k) if int(c)])
			memo[k] = p
			return p
	for i in range(m + 1):
		solve(i)
	return memo[m]
n = int(input())
print(dsolve(n))


import os.path
from math import gcd, floor, ceil
from collections import *
from bisect import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	ans = 0
	n = inp()
	while n:
		n -= max(list(map(int, str(n))))
		ans += 1
	pr(ans)
for _ in range(1):
	solve()


s = input()
n = int(s)
ans = 0
while n != 0:
	for i in range(9, 0, -1):
		if str(i) in str(n):
			n -= i
			ans += 1
			break
print(ans)


s = input()
n = int(s)
ans = 0
while n != 0:
	n -= int(max(s))
	s = str(n)
	ans += 1
print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
x = 0
while n > 0:
	n -= max([int(i) for i in list(str(n))])
	x += 1
print(x)


(n, a) = (int(input()), 0)
while n:
	n -= int(max(str(n)))
	a += 1
print(a)


k = int(input())
mini = []
mini.append(0)
for i in range(k):
	p = i + 1
	if p < 10:
		mini.append(1)
	else:
		digits = [int(d) for d in str(p)]
		mini.append(1000000)
		for d in range(len(digits)):
			mini[p] = min(mini[p], 1 + mini[p - digits[d]])
print(mini[k])


n = int(input())
count = 0
while n:
	n -= max((int(i) for i in str(n)))
	count += 1
print(count)


count = 0
n = int(input())
if n == 0:
	print(0)
	exit()
if n < 10:
	print(1)
	exit()
while n > 10:
	t = n
	z = float('-inf')
	r = 1
	while t:
		r = r + 1
		t1 = t % 10
		t = t // 10
		z = max(z, t1)
	n = n - z
	count = count + 1
print(count + 2)


n = int(input())
res = 0
while n != 0:
	mx = 0
	for (i, x) in enumerate(str(n)):
		if int(x) > mx:
			mx = int(x)
	n -= mx
	res += 1
print(res)


n = int(input())
oper = 0
while n >= 10:
	n -= max(map(int, str(n)))
	oper += 1
print(oper + (1 if n != 0 else 0))


from sys import stdin
input_ = stdin.readline
magic_num = input_()
operations = 0
i = 0
while i < int(magic_num):
	if magic_num == 0:
		break
	max_num = max({int(x) for x in str(magic_num).strip()})
	magic_num = int(magic_num) - max_num
	operations += 1
print(operations)


n = int(input())

def calc_dec(n):
	dig = [int(x) for x in str(n)]
	mx = 0
	for i in dig:
		if i > mx:
			mx = i
	return n - mx
i = 0
while n != 0:
	n = calc_dec(n)
	i += 1
print(i)


n = int(input())
count = 0
while n != 0:
	n_max = max(set(str(n)))
	n = n - int(n_max)
	count = count + 1
print(count)


n = int(input())
steps = 0
while n != 0:
	n -= max([int(k) for k in str(n)])
	steps += 1
print(steps)


import math
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def opr(s):
	k = list(str(s)[:len(str(s))])
	return int(max(k))
n = inp()
dp = [0 for i in range(n + 1)]
dp[0] = 0
for i in range(1, n + 1):
	dp[i] = dp[i - opr(i)] + 1
print(dp[n])


n = int(input())
if 10 > n > 0:
	print(1)
	exit(0)
elif n == 0:
	print(0)
	exit(0)
dp = [2 for i in range(n)]
dp[0] = n
z = 1
while True:
	dp[z] = dp[z - 1] - int(max(str(dp[z - 1])))
	if dp[z] == 0:
		break
	z = z + 1
print(z)


def main():
	num = int(input())
	subs = 0
	while num != 0:
		mx = 0
		n = 0
		str_num = str(num)
		for i in range(0, len(str_num)):
			n = max(n, int(str_num[i]))
		num = int(str_num) - n
		subs += 1
	print(subs)
main()


n = int(input())
res = 0
while n:
	res += 1
	n -= max([int(ch) for ch in str(n)])
print(res)


a = input()
a = list(a)
count = 0
while int(''.join(a)) > 0:
	k = max(a)
	a = int(''.join(a)) - int(k)
	a = str(a)
	count += 1
	a = list(a)
print(count)


(n, c) = (int(input()), 0)
while n:
	n -= int(max(str(n)))
	c += 1
print(c)


def find(s):
	i = 9
	while s.find(str(i), 0, len(s) + 1) == -1:
		i = i - 1
	s = str(int(s) - i)
	return s
n = int(input())
if n == 0:
	print(0)
	exit(0)
s1 = str(n)
ans = 0
while int(find(s1)) != 0:
	s1 = find(s1)
	ans = ans + 1
print(ans + 1)


import sys
from math import sqrt, floor, factorial, gcd
from collections import deque, Counter
inp = sys.stdin.readline
read = lambda : list(map(int, inp().strip().split()))

def solve():
	n = int(inp())
	s = 0
	while n > 0:
		m = n % 10
		t = n
		while t > 0:
			m = max(m, t % 10)
			t //= 10
		n -= m
		s += 1
	print(s)
solve()


n = int(input())
res = 0
while n > 0:
	tmp = int(max(str(n)))
	n -= tmp
	res += 1
print(res)


n = int(input())
temp = [-1 for i in range(n)]
c = 0
while n != 0:
	ns = list(str(n))
	m = max(ns)
	n = n - int(m)
	c += 1
print(c)


def largest_digit(num):
	largest = 0
	for digit in str(num):
		if int(digit) > largest:
			largest = int(digit)
	return largest

def solve(num):
	i = 0
	while num > 0:
		i += 1
		num = num - largest_digit(num)
	return i
num = int(input())
print(solve(num))


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	try:
		n = inp()
		ans = 0
		while n:
			ans += 1
			n -= max([int(i) for i in str(n)])
		print(ans)
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def max_digit(n):
	x = []
	n = str(n)
	for i in range(0, len(n)):
		x.append(int(n[i]))
	c = int(max(x))
	return c
n = int(input())
y = 0
while n != 0:
	x = max_digit(n)
	n = n - int(x)
	y += 1
print(y)


n = int(input())
nmaks = 0
hasil = 0
cek = n
while n > 0:
	nmaks = 0
	cek = n
	if n > 9:
		while cek > 0:
			if cek % 10 > nmaks:
				nmaks = cek % 10
			cek = cek // 10
	else:
		nmaks = n
	n -= nmaks
	hasil += 1
print(hasil)


n = int(input())
num = 0
while True:
	x = list(map(int, str(n)))
	if n == 0:
		break
	n -= max(x)
	num += 1
print(num)


import math

def to_digits(n):
	return [int(d) for d in str(n)]

def to_integer(digits):
	accum = 0
	factor = 1
	for d in reversed(digits):
		accum += factor * d
		factor *= 10
	return accum

def split(digits):
	d = 0
	index = 0
	for i in range(len(digits)):
		if digits[i] >= d:
			d = digits[i]
			index = i
	return (d, digits[i:])
memoize = {}

def num(x):
	y = 0
	while x > 0:
		digits = to_digits(x)
		(d, r) = split(digits)
		rint = to_integer(r)
		n = rint // d
		mod = rint % d
		if mod == 0 and n != 0:
			n = n
		elif rint < d or d < rint:
			n = n + 1
		y += n
		x = x - n * d
	return y
x = int(input())
print(num(x))


n = int(input())
s = str(n)
c = 0
while int(s) != 0:
	d = max(s)
	s = str(int(s) - int(d))
	c += 1
print(c)


n = int(input())
l = list(str(n))
n = int(n)
c = 0
while n != 0:
	m = max(list(str(n)))
	n -= int(m)
	c += 1
print(c)


from collections import Counter

def main():
	n = int(input())
	dp = Counter()
	elms = [n]
	dp[n] = 0
	while elms:
		e = elms.pop()
		m = max([int(c) for c in str(e)])
		if m > 0:
			if dp[e] + 1 < dp[e - m] or dp[e - m] == 0:
				dp[e - m] = dp[e] + 1
				elms.append(e - m)
	print(dp[0])
main()


a = int(input())
i = 0
while a != 0:
	i += 1
	x = max(list(map(int, list(str(a)))))
	a -= x
print(i)


n = int(input())
ans = 0
while n != 0:
	p = int(max(list(str(n))))
	n -= p
	ans += 1
print(ans)


import sys
import os.path
import math
from sys import stdin, stdout
from collections import *
from math import gcd, ceil, floor
mod = int(1000000000.0 + 7)
m1 = float('inf')
if os.path.exists('Updated prg/Input3d.txt'):
	sys.stdout = open('Updated prg/Output3d.txt', 'w')
	sys.stdin = open('Updated prg/Input3d.txt', 'r')

def sinp():
	return input()

def ninp():
	return int(sinp())

def mapinp():
	return map(int, sinp().split())

def smapinp():
	return map(str, sinp().split())

def linp():
	return list(mapinp())

def sl():
	return list(sinp().split())

def prnt(a):
	print(a)

def prntl(a):
	print(a, end=' ')

def prntlist(l1):
	print(*l1)

def power(n):
	return 1 << n
n = ninp()
a = str(n)
a = list(a)
c = 0
while n != 0:
	m1 = max(a)
	n = n - int(m1)
	c = c + 1
	a = str(n)
	a = list(a)
prnt(c)


import sys
fin = sys.stdin
n = int(fin.readline())
count = 0
while n > 0:
	count += 1
	n -= max(map(int, str(n)))
print(count)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())

def m(n):
	s = 0
	while n != 0:
		s = max(s, n % 10)
		n //= 10
	return s
n = I()
c = 0
while n != 0:
	n -= m(n)
	c += 1
print(c)


import math
import sys
input = sys.stdin.readline
n = int(input())
opt = 0
while n != 0:
	n -= int(max(list(str(n))))
	opt += 1
print(opt)


def get_max_digit(x):
	max_d = 0
	while x > 0:
		max_d = max(max_d, x % 10)
		x //= 10
	return max_d
n = int(input())
cnt = 0
while n > 0:
	d = get_max_digit(n)
	n -= d
	cnt += 1
print(cnt)


n = int(input())
cnt = 0
while n:
	m = -1
	for i in str(n):
		m = max(m, int(i))
	n -= m
	cnt += 1
print(cnt)


(n, res) = (int(input()), 1)
if n != 0:
	while len(str(n)) > 1:
		res += 1
		n -= max(list(map(int, str(n))))
	print(res)
else:
	print('0')


n = int(input())
i = [int(x) for x in str(n)]
sum = 0
while True:
	if n != 0:
		n -= max(i)
		sum += 1
		i = [int(x) for x in str(n)]
		if n == 0:
			break
	else:
		break
print(sum)


def maxx(n):
	l = []
	while n > 0:
		l.append(n % 10)
		n = int(n / 10)
	return max(l)
n = int(input())
j = 0
while n > 0:
	n = n - maxx(n)
	j += 1
print(j)


def getMaxDigit(n, c):
	while n > 0:
		t = n
		m = 0
		while t:
			if t % 10 > m:
				m = t % 10
			t = t // 10
		c += 1
		n = n - m
	return c
n = int(input())
print(getMaxDigit(n, 0))


n = int(input())
s = 0
while n > 0:
	a = list(str(n))
	a.sort()
	n -= int(a[-1])
	s += 1
print(s)


n = int(input())

def isb(n):
	re = -1
	while n > 0:
		tmp = n % 10
		re = max(re, tmp)
		n //= 10
	return re
ans = 0
while n > 0:
	n -= isb(n)
	ans += 1
print(ans)


def greatestDigit(n):
	res = 0
	while n > 0:
		res = max(res, n % 10)
		n = n // 10
	return res

def solve(magicNum):
	if magicNum == 0:
		return 0
	res = 0
	while magicNum > 0:
		maxDig = greatestDigit(magicNum)
		magicNum -= maxDig
		res += 1
	return res
magicNum = int(input())
print(solve(magicNum))


n = input()
l = []
for i in n:
	l.append(int(i))
count = 0
while True:
	l = []
	for i in n:
		l.append(int(i))
	if int(n) == 0:
		break
	else:
		n = str(int(n) - max(l))
		count += 1
print(count)


n = input()
p = 0
while int(n) != 0:
	if len(n) == 1:
		p += 1
		break
	l = [int(i) for i in n]
	n = str(int(n) - max(l))
	p += 1
print(p)


n = input()
ans = 0
while max(n) != '0':
	t = max(n)
	k = int(n) - int(t)
	n = str(k)
	ans += 1
print(ans)


n = int(input())
k = 0
while n > 0:
	x = int(max(list(str(n))))
	n -= x
	k += 1
print(k)


def solve(n):
	count = 0
	while n != 0:
		p = str(n)
		mx = p[0]
		for i in p:
			mx = max(mx, i)
		n -= int(mx)
		count += 1
	return count
n = int(input())
print(solve(n))


n = str(input())
steps = 0
while int(n) != 0:
	temp = 0
	for i in n:
		temp = int(max(int(i), temp))
	n = str(int(n) - temp)
	steps += 1
print(steps)


n = int(input())
o = 0
while n > 0:
	n -= int(max(str(n)))
	o += 1
print(o)


n = int(input())

def max_digit(n):
	max_dig = -1
	while n > 0:
		if n % 10 > max_dig:
			max_dig = n % 10
		n //= 10
	return max_dig
count = 0
while n != 0:
	if n == 0:
		break
	n -= max_digit(n)
	count += 1
print(count)


(n, counter) = (int(input()), 0)
while n > 0:
	n -= int(max(str(n)))
	counter += 1
print(counter)


from sys import stdin
input = lambda : stdin.readline()
from math import ceil, sqrt, gcd
n = int(input())
count = 0
while n != 0:
	n -= int(max(list(str(n))))
	count += 1
print(count)


num = int(input())
ans = 0
while num != 0:
	L = list(str(num))
	d = int(max(L))
	num -= d
	ans += 1
print(ans)


n = int(input())
ans = 0
while n > 0:
	n -= max(map(int, str(n)))
	ans += 1
print(ans)


import math
from math import gcd, floor, sqrt, log

def iin():
	return int(input())

def sin():
	return input().strip()

def listin():
	return list(map(int, input().strip().split()))

def liststr():
	return list(map(str, input().strip().split()))

def ceill(x):
	return int(x) if x == int(x) else int(x) + 1

def ceilldiv(x, d):
	x // d if x % d == 0 else x // d + 1

def LCM(a, b):
	return a * b // gcd(a, b)
n = iin()
cnt = 0
while n > 0:
	n -= int(max(str(n)))
	cnt += 1
print(cnt)


s = int(input())
count = 0
while s > 0:
	s -= int(max(str(s)))
	count += 1
print(count)


def findMaxDigit(x):
	ans = x % 10
	x //= 10
	while x > 0:
		if ans < x % 10:
			ans = x % 10
		if ans == 9:
			return ans
		x //= 10
	return ans
n = int(input())
count = 0
while n > 0:
	tmp = findMaxDigit(n)
	n -= tmp
	count += 1
print(count)


m = int(input())
a = 0
while m > 0:
	m -= int(max([int(i) for i in str(m)]))
	a += 1
print(a)


y = int(input())
c = 0
while y != 0:
	y -= int(max(str(y)))
	c += 1
print(c)


n = int(input())
dp = [0] * (n + 1)
for i in range(1, n + 1):
	tmp = i
	dp[i] = 10 ** 18
	while tmp > 0:
		d = tmp % 10
		tmp //= 10
		dp[i] = min(dp[i], dp[i - d])
	dp[i] += 1
print(dp[n])


num = int(input())
count = 0
while num != 0:
	lst = [int(i) for i in str(num)]
	num -= max(lst)
	count += 1
print(count)


def solve(n):
	mem = [0] * (n + 1)
	mem[1:10] = [1] * 9
	for i in range(10, n + 1):
		digits = set([int(c) for c in str(i) if c != '0'])
		m = 1000000
		for d in digits:
			k = 1 + mem[i - d]
			if k < m:
				m = k
		mem[i] = m
	return mem[n]
print(solve(int(input())))


sums = int(input())
count = 0
while sums != 0:
	stringg = str(sums)
	maxi = max(stringg)
	sums = sums - int(maxi)
	count = count + 1
print(count)

def countways(n):
	if n == 1:
		return 0
	elif n % 2 == 0:
		return 1 + countways(n / 2)
	else:
		return 1 + min(countways(n - 1), countways(n + 1))


t = int(input())
c = 0
while t != 0:
	c += 1
	t = t - int(max(str(t)))
print(c)


n = int(input())

def maxDigit(a):
	x = 9
	while x > 0:
		if str(x) in str(a):
			return x
		else:
			x -= 1
	return 0
memo = 0
while n != 0:
	n = n - maxDigit(n)
	memo += 1
print(memo)


n = int(input())
s = 0
while n != 0:
	u = list(str(n))
	u.sort()
	n -= int(u[-1])
	s += 1
print(s)


def main():
	n = int(input())
	ans = 0
	while n != 0:
		s = str(n)
		n -= int(max(s))
		ans += 1
	print(ans)
main()


memoization_table = {}

def compute_count(previous_max, rest):
	global memoization_table
	original_rest = rest
	if (previous_max, rest) in memoization_table:
		return memoization_table[previous_max, rest]
	num_digits = len(str(rest))
	if num_digits == 1:
		memoization_table[previous_max, original_rest] = (1, min(0, rest - previous_max))
		return (1, min(0, rest - previous_max))
	sum_count = 0
	while rest > 0:
		s = str(rest).zfill(num_digits)
		new_max = max(previous_max, int(s[0]))
		new_rest = int(s[1:])
		(count, leftover) = compute_count(new_max, new_rest)
		sum_count += count
		rest -= new_rest
		rest += leftover
	memoization_table[previous_max, original_rest] = (sum_count, rest)
	return (sum_count, rest)
n = int(input())
ans = 0
if n != 0:
	(ans, not_ans) = compute_count(0, n)
print(ans)


n = int(input())
c = 0
while n > 0:
	maxd = 0
	if n <= 50 and n % 10 == 0:
		c += 2 * n // 10
		n = 0
		break
	for ch in str(n):
		maxd = max(maxd, int(ch))
	n -= maxd
	c += 1
print(c)


s = list(input())
cnt = 0
if len(s) == 1 and int(s[0]) == 0:
	print(0)
else:
	while True:
		k = sorted(s)
		maxx = int(k[-1])
		s = list(str(int(''.join(s)) - maxx))
		cnt += 1
		if len(s) == 1 and int(s[0]) <= 0:
			break
	print(cnt)


q = int(input())
k = 0
while q != 0:
	w = list(map(int, list(str(q))))
	e = max(w)
	q -= e
	k += 1
print(k)


n = int(input())
ans = 0
while n > 0:
	digits = list(map(lambda x: int(x), str(n)))
	max_d = max(digits)
	n -= max_d
	ans += 1
print(ans)


n = list(input())
s = 0
while int(''.join(n)) > 0:
	k = int(max(n))
	n = int(''.join(n))
	n -= k
	n = [str(i) for i in str(n)]
	s += 1
print(s)


mem = {}

def compute_count(pmax, re):
	global mem
	ore = re
	if (pmax, re) in mem:
		return mem[pmax, re]
	numdig = len(str(re))
	if numdig == 1:
		mem[pmax, ore] = (1, min(0, re - pmax))
		return (1, min(0, re - pmax))
	sc = 0
	while re > 0:
		s = str(re).zfill(numdig)
		nmax = max(pmax, int(s[0]))
		newre = int(s[1:])
		(cnt, left) = compute_count(nmax, newre)
		sc += cnt
		re -= newre
		re += left
	mem[pmax, ore] = (sc, re)
	return (sc, re)
x = int(input())
if x:
	print(compute_count(0, x)[0])
else:
	print(0)


n = int(input())
dp = [0] + [1000000000.0 + 7] * n
for i in range(1, n + 1):
	tmp = i
	while tmp:
		dp[i] = min(dp[i], dp[i - tmp % 10] + 1)
		tmp //= 10
print(int(dp[n]))


from sys import stdin, stdout
from math import gcd, sqrt, factorial, inf
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 0 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7

def max_int(n):
	m = -inf
	while n:
		m = max(m, n % 10)
		n //= 10
	return m
n = I()
ans = 0
while n:
	ans += 1
	n -= max_int(n)
print(ans)


n = str(input())
a = []
for i in range(len(n)):
	a.append(int(n[i]))
(b, c) = (int(n), 0)
while b != 0:
	b -= max(a)
	a = []
	v = str(b)
	for i in range(len(v)):
		a.append(int(v[i]))
	c += 1
print(c)


s = input()
r = 0
h = int(s)
while 1:
	l = list(s)
	d = list(map(int, s))
	n = ''.join(l)
	m = int(n)
	f = max(d)
	m = m - f
	s = str(m)
	r += 1
	if m <= 0:
		break
print(0 if h == 0 else r)


liczba = int(input())
wynik = 0
while liczba != 0:
	maks = 0
	for x in str(liczba):
		maks = max(maks, int(x))
	liczba -= maks
	wynik += 1
print(wynik)


n = int(input())
count = 0
while n:
	maxi = 0
	nn = n
	while nn:
		maxi = max(maxi, nn % 10)
		nn //= 10
	count += 1
	n -= maxi
print(count)


s = int(input())
cnt = 0
while s:
	s -= max(map(int, str(s)))
	cnt += 1
print(cnt)


def main():
	cur = int(input())
	ans = 0
	while cur > 0:
		ans += 1
		m = max((int(c) for c in str(cur)))
		cur -= m
	print(ans)
main()


def findMax(N):
	Max = 0
	while N != 0:
		Rem = N % 10
		N = N // 10
		Max = max(Max, Rem)
	return Max
N = int(input())
count = 0
while N != 0:
	X = findMax(N)
	N -= X
	count += 1
print(count)


n = input()
tmp = int(n)
i = 0
while tmp != 0:
	sub = max([int(x) for x in str(tmp)])
	tmp -= sub
	i += 1
print(i)


n = input()
if n == '0':
	print(0)
else:
	count = 0
	while int(n) != 0:
		b = max(n)
		n = str(int(n) - int(b))
		count += 1
	print(count)


n = int(input())

def naive(n):
	c = 0
	while n != 0:
		c += 1
		n -= max([int(x) for x in list(str(n))])
	print(c)
naive(n)


n = int(input())
answer = [-1] * (n + 1)
answer[0] = 0

def digits(x):
	return [int(i) for i in str(x)]
for i in range(1, n + 1):
	pretendents = []
	for digit in digits(i):
		if digit != 0:
			pretendents.append(answer[i - digit])
	answer[i] = min(pretendents) + 1
print(answer[n])


start = input()
counter = 0
sInt = int(start)
while sInt != 0:
	sInt -= max([int(c) for c in start])
	start = str(sInt)
	counter += 1
print(counter)


i = input()
x = int(i)
cont = 0
while x:
	x -= int(max(i))
	i = str(x)
	cont += 1
print(cont)


n = int(input())
c = 0
while n > 0:
	k = n
	maxx = 0
	while k > 0:
		maxx = max(maxx, k % 10)
		k = k // 10
	n -= maxx
	c += 1
print(c)