You are given a positive integer $n$.

Let $S(x)$ be sum of digits in base 10 representation of $x$, for example, $S(123) = 1 + 2 + 3 = 6$, $S(0) = 0$.

Your task is to find two integers $a, b$, such that $0 \leq a, b \leq n$, $a + b = n$ and $S(a) + S(b)$ is the largest possible among all such pairs.


-----Input-----

The only line of input contains an integer $n$ $(1 \leq n \leq 10^{12})$.


-----Output-----

Print largest $S(a) + S(b)$ among all pairs of integers $a, b$, such that $0 \leq a, b \leq n$ and $a + b = n$.


-----Examples-----
Input
35

Output
17

Input
10000000000

Output
91



-----Note-----

In the first example, you can choose, for example, $a = 17$ and $b = 18$, so that $S(17) + S(18) = 1 + 7 + 1 + 8 = 17$. It can be shown that it is impossible to get a larger answer.

In the second test example, you can choose, for example, $a = 5000000001$ and $b = 4999999999$, with $S(5000000001) + S(4999999999) = 91$. It can be shown that it is impossible to get a larger answer.

Difficulty: EASY

Solutions:
def digisum(n):
	sum = 0
	while n != 0:
		sum += n % 10
		n = n // 10
	return sum

def give9(n):
	num9 = 0
	while n >= 10:
		num9 = num9 * 10 + 9
		n = n // 10
	return num9

def method3(n):
	a = give9(n)
	b = n - a
	return digisum(a) + digisum(b)
n = int(input())
print(method3(n))


def sod(n):
	c = 0
	while n > 0:
		c += n % 10
		n //= 10
	return c
n = int(input())
s = '0'
c = 0
while int(s) <= n:
	s += '9'
	c += 1
c -= 1
print(c * 9 + sod(n - int(s[:len(s) - 1])))


n = input()
new_number = ''.join(['9' for _ in range(len(n) - 1)])
new_number = str(int(n[0]) - 1) + new_number
a = int(new_number)
b = int(n) - a
a = list(str(a))
b = list(str(b))
l = a + b
soma = 0
for i in l:
	soma += int(i)
print(soma)


x = input()
a = int(x)
x = str(a // 2)
b = str(int(x[0]))
for i in ['9'] * (len(x) - 1):
	b += i
b = int(b)
a -= b
ans = 0
for i in str(a) + str(b):
	ans += int(i)
print(ans)


n = int(input())
s = [int(x) for x in str(n)]
s.reverse()
k = s[-1]
m = len(s)
l = str(k - 1) + (m - 1) * '9'
l = int(l)
m = n - l
a = [int(x) for x in str(l)]
b = [int(x) for x in str(m)]
print(sum(a) + sum(b))


n = int(input())
a = n
b = 0
lisa = list(map(int, str(a)))
lisb = list(map(int, str(b)))
k = len(lisa) - 1
while k > 0:
	if lisa[k] != 9:
		lisb[b] += 1 + lisa[k]
		lisa[k] = 9
		lisa[k - 1] -= 1
	k -= 1
print(sum(lisa + lisb))


x = int(input())
last = x
p = 1
while last > 0:
	if int(last / 10) <= 0:
		val = last % 10
	else:
		p = p * 10
	last = int(last / 10)
one = val * p - 1
sec = x - one
s = 0
while one > 0:
	s = s + one % 10
	one = int(one / 10)
while sec > 0:
	s = s + sec % 10
	sec = int(sec / 10)
print(s)


s = input()
su = sum(map(int, list(s)))
while len(s) > 0 and s[-1] == '9':
	s = s[:-1]
print(su + 9 * max(0, len(s) - 1))


n = int(input())
x = 0

def cal(num):
	res = 0
	while num:
		res += num % 10
		num //= 10
	return res
c = 0
while x * 10 + 9 <= n:
	x = x * 10 + 9
	c += 1
print(c * 9 + cal(n - x))


n = int(input())
k = 0

def sum(n):
	summ = 0
	while n > 0:
		summ += n % 10
		n //= 10
	return summ
for i in range(0, 14, 1):
	if n < 10 ** i:
		k = i
		break
a = 10 ** (k - 1) - 1
l = 0
for i in range(1, 10, 1):
	if n < i * 10 ** (k - 1) + a:
		l = i - 1
		break
h = n - (l * 10 ** (k - 1) + a)
a = sum(h)
print(9 * (k - 1) + l + a)


def s(a):
	sum = 0
	for ch in str(a):
		sum += int(ch)
	return sum
n = int(input())
if n < 10:
	print(n)
else:
	l = len(str(n))
	a = int('9' * (l - 1))
	sa = 9 * (l - 1)
	sb = s(n - a)
	print(sa + sb)


n = int(input())
num1 = 10 ** (len(str(n + 1)) - 1) - 1
num2 = n - num1
num1 = [int(x) for x in list(str(num1))]
num2 = [int(x) for x in list(str(num2))]
print(sum(num1) + sum(num2))


import sys
n = input()
if len(n) == 1:
	print(n)
	sys.exit()
c = '9' * (len(n) - 1)
nc = int(n) - int(c)
print(sum(map(int, str(nc) + c)))


inp = input()
n = int(inp)
h = inp[1:]
b = False
ans = 0
for t in h[::-1]:
	p = int(t)
	if not b and p == 9:
		ans += 9
	elif not b:
		ans += 10 + p
		b = True
	else:
		ans += 9 + p
		b = True
if n < 10:
	print(n)
else:
	print(ans + int(inp[0]) - (1 if b else 0))


n = int(input())

def s(n):
	if n < 10:
		return n
	return s(n % 10) + s(n // 10)
h = n // 2
k = str(h)
t = int(k[0] + '9' * (len(k) - 1))
print(s(t) + s(n - t))


from math import pow

def sumofdigits(n):
	a = list(str(n))
	x = list(map(int, a))
	return sum(x)
n = int(input())
t = len(str(n))
if n <= 10:
	print(n)
else:
	x = n // pow(10, t - 1)
	a = x * pow(10, t - 1) - 1
	print(sumofdigits(int(n - a)) + sumofdigits(int(a)))


n = int(input())
if n < 10:
	print(n)
else:
	l = len(str(n)) - 1
	p = int('9' * l)
	t = n - p
	s = 0
	while t > 0:
		s += t % 10
		t //= 10
	print(s + 9 * l)


def sum_digits3(n):
	r = 0
	while n:
		(r, n) = (r + n % 10, n // 10)
	return r
a = input()
n = int(a)
l = len(a)
if l == 1:
	print(n)
else:
	b = '1'
	b += '9' * (l - 1)
	sum_b = 9 * (l - 1) + 1
	if a[0] == '1':
		b = '9' * (l - 1)
		sum_b = 9 * (l - 1)
	b = int(b)
	a = n - b
	print(sum_digits3(a) + sum_b)


n = input()
if len(n) == 1:
	print(n)
else:
	k = '9' * (len(n) - 1)
	print(9 * (len(n) - 1) + sum(list(map(int, str(int(n) - int(k))))))


def digit_sum(num):
	res = 0
	while num != 0:
		res += num % 10
		num //= 10
	return res

def main():
	n = int(input())
	a = n - n % 10 ** (len(str(n)) - 1) - 1
	b = n - a
	print(digit_sum(a) + digit_sum(n - a))
main()


n = input()
print(sum((int(i) for i in str(int(n[0]) * 10 ** (len(n) - 1) - 1))) + sum((int(i) for i in str(int(n) - (int(n[0]) * 10 ** (len(n) - 1) - 1)))))


n = int(input())
t = len(str(n))
if t == 1:
	x = 0
else:
	x = int((t - 1) * '9')
y = n - x

def sm(x):
	res = 0
	for i in str(x):
		res += int(i)
	return res
print(sm(x) + sm(y))


n = input()
x = len(n)
if x >= 2:
	m1 = int('9' * (x - 1))
else:
	m1 = 0
m2 = int(n) - m1
ANS = 0
for i in str(m1) + str(m2):
	ANS += int(i)
print(ANS)


a = list(map(str, input()))
if len(a) == 1:
	print(a[0])
	exit()
s = [a[0]] + ['0' for i in range(len(a) - 1)]
s = ''.join(s)
s = int(s) - 1
a = int(''.join(a))
d = a - s
s = list(str(s))
d = list(str(d))
for i in range(len(s)):
	s[i] = int(s[i])
for i in range(len(d)):
	d[i] = int(d[i])
print(sum(s) + sum(d))


import math

def S(n):
	value = 0
	while n > 0:
		value += n % 10
		n //= 10
	return value

def optimal_a(n):
	lg = int(math.log10(n + 1e-05))
	value = 0
	while lg > 0:
		value *= 10
		value += 9
		lg -= 1
	return value
n = int(input())
a = optimal_a(n)
res = S(a) + S(n - a)
print(res)


def s(a):
	count = 0
	for x in str(a):
		count = count + int(x)
	return count
n = int(input())
a = 9
while a < n:
	a = a * 10 + 9
a = a // 10
b = n - a
print(s(a) + s(b))


def calc(num):
	if num == 0:
		return 0
	sum = 0
	s = str(num)
	for ch in s:
		sum += int(ch)
	return sum

def g9(n):
	sn = str(n)
	tn = ''
	for i in range(len(sn) - 1):
		tn += '9'
	if tn != '':
		return int(tn)
	else:
		return 0
ans = []
n = int(input())
ans.append(calc(n // 2) + calc(n - n // 2))
if n // 2 - 1 >= 0:
	ans.append(calc(n // 2 - 1) + calc(n - (n // 2 - 1)))
num = g9(n)
ans.append(calc(num) + calc(n - num))
print(max(ans))


n = int(input())
if n < 19:
	print(n)
else:
	n2 = len(str(n))
	n3 = int('9' * (n2 - 1))
	n4 = n - n3
	print(sum(list(map(int, list(str(n3))))) + sum(list(map(int, list(str(n4))))))


n = int(input())

def sumdig(n):
	s = 0
	while n != 0:
		s += n % 10
		n //= 10
	return s
k = n // 2
p = str(n)
l = str(int(p[0]) - 1)
u = p[0]
for i in range(len(p) - 1):
	l = l + '9'
	u = u + '9'
l = int(l)
u = int(u)
if k - l > u - k:
	print(sumdig(u) + sumdig(n - u))
else:
	print(sumdig(l) + sumdig(n - l))


n = input()
if len(n) == 1:
	print(n)
else:
	c = str(int(n) - int('9' * (len(n) - 1)))
	s = 0
	for x in c:
		s += int(x)
	print(9 * (len(n) - 1) + s)


def main():
	n = int(input())
	pad = ''
	while int(pad + '9') <= n:
		pad += '9'
	for i in range(9, -1, -1):
		if int(str(i) + pad) <= n:
			pad = str(i) + pad
			break
	print(sum(map(int, list(pad))) + sum(map(int, list(str(n - int(pad))))))
main()


n = int(input())
if len(str(n)) == 1:
	print(n)
else:
	x = int('9' * (len(str(n)) - 1))
	y = n - x
	s = 0
	for i in str(x):
		s += int(i)
	for i in str(y):
		s += int(i)
	print(s)


n = int(input())
s = '9'
while int(s) <= n:
	s += '9'
s = s.replace('9', '', 1)
if s == '':
	s = '0'
a = [int(q) for q in s]
b = [int(q) for q in str(n - int(s))]
print(sum(a) + sum(b))


n = int(input())

def get_bs(n):
	bs = 0
	while n > 0:
		bs += n % 10
		n = n // 10
	return bs
n_str = str(n)
lenn = len(n_str) - 1
base = 10 ** lenn * int(n_str[0]) - 1
rest = n - base
max_bs = get_bs(base) + get_bs(rest)
print(max_bs)


import sys
import math

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

def get_list():
	return list(get_ints())

def printspx(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')

def printchk(*args):
	return print(*args, end=' \\ ')
MODPRIME = int(1000000000.0 + 7)
BABYMODPR = 998244353
n = input()
ans = 9 * (len(n) - 1)
ans += int(n[0]) - 1
s = '9' * (len(n) - 1)
s = str(int(n[0]) - 1) + s
s1 = int(n) - int(s)
while s1:
	ans += s1 % 10
	s1 //= 10
print(ans)


n = input()
try:
	a = int('9' * (len(n) - 1))
	b = int(n) - a
	s = str(a) + str(b)
	total = 0
	for x in s:
		total += int(x)
	print(total)
except:
	print(n)


n = int(input())
if n <= 9:
	print(n)
	raise SystemExit
nna2 = str(n // 2)
a = list(str(str(nna2[0:len(nna2) - 1]) + '9'))
maina = ''
for (q, i) in enumerate(a):
	if q != 0:
		maina += '9'
	else:
		maina += a[0]
b = list(str(n - int(maina)))
sum_a = sum([int(x) for x in list(maina)])
sum_b = sum([int(y) for y in b])
print(sum_a + sum_b)


def sumofdig(num):
	if num > 0:
		return num % 10 + sumofdig(num // 10)
	return 0
n = int(input())
a = '0'
while True:
	a += '9'
	if int(a) > n:
		a = a[0:len(a) - 1]
		break
a = int(a)
b = n - a
print(sumofdig(a) + sumofdig(b))


n = int(input())

def somme(x):
	k = 0
	ch = str(x)
	if x == 0:
		return 0
	else:
		for i in range(len(ch)):
			d = int(ch[i])
			k = k + d
		return k
a = 0
while a * 10 + 9 <= n:
	a = a * 10 + 9
b = n - a
s1 = somme(a)
s2 = somme(b)
print(s1 + s2)


def s(n):
	n = str(n)
	n = list(map(int, n))
	return sum(n)
n = int(input())
if n < 10:
	print(n)
	exit(0)
t = int('9' * (len(str(n)) - 1))
print(s(t) + s(n - t))


def S(n):
	if n == 0:
		return 0
	else:
		return n % 10 + S(n // 10)
n = input()
l = len(n)
n = int(n)
if l == 1:
	print(n)
else:
	a = int('9' * (l - 1))
	print(S(a) + S(n - a))


n = int(input())
sa = 9
pio = 0
tim = 0
if n < 10:
	print(n)
else:
	for y in range(7474):
		if int(str(sa) + '9') <= n:
			sa = int(str(sa) + '9')
		else:
			kam = n - sa
			for it in str(sa):
				pio += int(it)
			for item in list(str(kam)):
				tim += int(item)
			break
	print(pio + tim)


a = int(input())
if a > 9:
	d = a
	i = 0
	while d > 0:
		y = d
		d = d // 10
		i += 1
	w = a // 10 ** (i - 1) * 10 ** (i - 1) - 1
	y = a - w

	def sum123(a):
		global sum, s
		sum = 0
		while a > 0:
			s = a % 10
			sum += s
			a = a // 10
		return sum
	sumend = sum123(w) + sum123(y)
	print(sumend)
else:
	print(a)


n = input()
l = len(n) - 1
if l > 0:
	x = '9' * l
else:
	x = 0
x = int(x)
y = int(n) - x
sum = 0
while x:
	sum += x % 10
	x //= 10
while y:
	sum += y % 10
	y //= 10
print(sum)


num = list(map(int, reversed(list(input()))))
n = len(num)
sumDigit = 0
for i in range(n):
	sumDigit += num[i]
	if i + 1 < n and num[i] < 9:
		sumDigit += 10
		num[i + 1] -= 1
print(sumDigit)


m = int(input())
mm = m
ms = []
c = 0
a = 1
b = 1
if m < 10:
	print(m)
	exit(0)
for x in range(1, len(str(m)), +1):
	ms.append('9')
if str(m)[0] != '1':
	ms.insert(0, str(int(list(str(m))[0]) - 1))
ms_int = int(''.join(ms))
b_int = m - ms_int
wyn = 0
for x in ms:
	wyn += int(x)
for x in list(str(b_int)):
	wyn += int(x)
print(wyn)


n = int(input())
n_decimal = 0
i = n
while i != 0:
	n_decimal += 1
	i //= 10
n1 = 10 ** (n_decimal - 1) - 1
n2 = n - n1
result1 = 0
num = n1
while num > 0:
	result1 += num % 10
	num //= 10
result2 = 0
num = n2
while num > 0:
	result2 += num % 10
	num //= 10
print(result1 + result2)


import math
n = input()
n = int(n)
x = math.log10(n)
str = '0'
x = int(x)
for i in range(x):
	str += '9'
k = int(str)
g = n - k
k1 = 0
g1 = 0
while k > 0:
	k1 += k % 10
	k //= 10
while g > 0:
	g1 += g % 10
	g //= 10
print(k1 + g1)


def somaDigitos(x):
	soma = 0
	while x > 0:
		resto = x % 10
		soma += resto
		x = x // 10
	return soma
n = int(input())
a = 0
b = n
x = somaDigitos(a) + somaDigitos(b)
maximo = x
lim = n // 2
i = 1
while a < n:
	a = int('9' * i)
	b = n - a
	if b > 0:
		x = somaDigitos(a) + somaDigitos(b)
		maximo = max(maximo, x)
	i += 1
print(maximo)


n = input()
l = len(n) - 1
k = int(n) - 10 ** l + 1
r = 9 * l
while k:
	r += k % 10
	k //= 10
print(r)


i = input()
if len(i) == 1:
	print(i)
else:
	d1 = '9' * (len(i) - 1)
	d2 = str(int(i) - int(d1))
	li = list(map(int, list(d1) + list(d2)))
	print(sum(li))


s = input()
if len(s) == 1:
	print(s)
else:
	first = '9' * (len(s) - 1)
	second = int(s) - int(first)
	ans = 0
	for i in str(first) + str(second):
		ans += int(i)
	print(ans)


def max_sum(x):
	digit = 0
	carry = 0
	power = 1
	result = [0, 0]
	while x > 0:
		digit = x % 10
		x //= 10
		if digit == 9 and carry == 0 or x == 0:
			result[0] += (digit - carry) * power
			carry = 0
		else:
			result[0] += 9 * power
			result[1] += (digit + 1 - carry) * power
			carry = 1
		power *= 10
	s = 0
	for n in result:
		while n > 0:
			s += n % 10
			n //= 10
	print(s)
max_sum(int(input()))


def trunc(n):
	s = 0
	while n != 0:
		s += n % 10
		n //= 10
	return s

def main():
	n = int(input())
	first = n // 10 ** (len(str(n)) - 1) * 10 ** (len(str(n)) - 1) - 1
	second = n - first
	return trunc(first) + trunc(second)
print(main())


def s(x):
	out = 0
	q = str(x)
	for i in q:
		out += int(i)
	return out
n = int(input())
if n <= 9:
	print(n)
	raise SystemExit
k = len(str(n))
a = n // 10 ** (k - 1)
if a >= 2:
	a = a - 1
	a = str(a) + '9' * (k - 1)
else:
	a = '9' * (k - 1)
a = int(a)
b = n - a
out = s(a) + s(b)
print(out)


def sod(a):
	sol = 0
	while a > 0:
		sol += a % 10
		a //= 10
	return sol
n = int(input())
ans = 0
a = 0
while a < n:
	ans = max(ans, sod(a) + sod(n - a))
	a = a * 10 + 9
print(ans)


def digit_sum(n):
	sum1 = 0
	while n > 0:
		sum1 += n % 10
		n = n // 10
	return sum1
for _ in range(1):
	s = input()
	if len(s) == 1:
		print(int(s))
		break
	s1 = s[1:]
	ns1 = int(s1) + 1
	print(digit_sum(int(s) - ns1) + digit_sum(ns1))


n = int(input())
t = n
c = 0
s = 0
while t != 0:
	c += 1
	t = t // 10
c -= 1
a = pow(10, c)
a = a * (n // a)
a -= 1
b = n - a
while a != 0 or b != 0:
	s += a % 10
	s += b % 10
	a = a // 10
	b = b // 10
print(s)


num = input()
count = 0
num1 = int(num) - 10 ** (len(num) - 1) + 1
for i in str(num1):
	count += int(i)
print((len(num) - 1) * 9 + count)


def summ(n):
	s = 0
	while n != 0:
		s += n % 10
		n //= 10
	return s
n = int(input())
x = 0
ans = -float('inf')
while x <= n:
	ans = max(ans, summ(x) + summ(n - x))
	x = x * 10 + 9
print(ans)


n = int(input())
d = n
a = n // 2 - 1
c = 1
while d >= 10:
	d = d // 10
	c = c * 10
a = c * d - 1
b = n - a
print(sum([int(x) for x in str(a)]) + sum([int(x) for x in str(b)]))


def max_sum(x):
	digit = 0
	carry = 0
	result = 0
	while x > 0:
		digit = x % 10
		x //= 10
		if digit == 9 and carry == 0 or x == 0:
			result += digit - carry
			carry = 0
		else:
			result += 10 + digit - carry
			carry = 1
	print(result)
max_sum(int(input()))


def sum_of_digits(n):
	sum_digits = 0
	while n > 0:
		sum_digits += n % 10
		n -= n % 10
		n //= 10
	return sum_digits
n = input()
if len(n) == 1:
	print(n)
else:
	x = pow(10, len(n) - 1) - 1
	print(sum_of_digits(x) + sum_of_digits(int(n) - x))


def sum(a):
	s = 0
	while a != 0:
		s = s + a % 10
		a = a // 10
	return s
n = int(input())
h = 0
a = n // 2
s = len(str(a))
w = '9' * (s - 1)
for i in range(10):
	j = int(str(i) + w)
	k = n - j
	if k >= 0:
		h = max(h, sum(j) + sum(k))
print(h)


def count(n):
	l = len(n) - 1
	n = int(n)
	s = 9 * l
	for i in range(l):
		ten = 10 ** i
		n -= 9 * ten
	while n > 0:
		s += n % 10
		n //= 10
	print(s)
n = input()
count(n)


def chan(x, f):
	n = 0
	p = x
	while True:
		if int(str(n) + x) > f:
			return p
		p = str(n) + x
		n = n + 1
		if n > 9:
			return x
n = int(input())
x = '9'
f = n
if n > 9:
	while int(x + '9') <= n:
		x = x + '9'
	x = chan(x, n)
	f = sum(map(int, list(x)))
	x = str(n - int(x))
	f = f + sum(map(int, list(x)))
print(f)


N = int(input())
s = str(N)
K = str(int(s[0]) - 1) + '9' * (len(s) - 1)
b = str(N - int(K))
ans = 0
for s in K:
	ans += int(s)
for s in b:
	ans += int(s)
print(ans)


def sum_dig(n):
	return sum([int(x) for x in list(str(n))])
n = int(input())
if n < 9:
	print(n)
else:
	a = 9
	while True:
		na = int(str(a) + '9')
		if na <= n:
			a = na
		else:
			break
	print(sum_dig(a) + sum_dig(n - a))


n = input()
l = len(n)
if l == 1:
	print(n)
else:
	l = l - 1
	k = ''
	for i in range(0, l):
		k = k + '9'
	k = int(k)
	n = int(n)
	re = n - k
	rem = 0
	while re > 0:
		rem = rem + re % 10
		re = re // 10
	print(9 * l + rem)


n = input()
if len(n) == 1:
	print(n)
	exit()
q = (len(n) - 1) * '9'
n = int(n)
p = n - int(q)
q = int(q)

def calc(x):
	num = 0
	while x > 0:
		num += x % 10
		x //= 10
	return num
print(calc(p) + calc(q))


q = int(input())
if len(str(q)) > 1:
	print(sum(map(int, list('9' * (len(str(q)) - 1)) + list(str(q - int('9' * (len(str(q)) - 1)))))))
else:
	print(q)


n = input()
if int(n) <= 10:
	print(n)
else:
	n1 = list(n)
	n2 = list(n)
	n1[0] = int(n[0]) - 1
	n2[0] = str(int(n[0]) - 1)
	for i in range(1, len(n)):
		n1[i] = 9
		n2[i] = str(9)
	k = list(str(int(n) - int(''.join(n2))))
	for i in range(len(k)):
		k[i] = int(k[i])
	print(sum(k) + sum(n1))


def numsum(x):
	sum = 0
	while x != 0:
		sum = sum + x % 10
		x = x // 10
	return sum
inp = int(input())
futurereference = inp
holder = inp
b = 1
while inp != 0:
	current = (inp - 1) * b + (b - 1)
	if numsum(current) >= numsum(holder):
		holder = current
	inp = inp // 10
	b = b * 10
m = holder
n = futurereference - holder
digitsum = 0
for digit in str(m):
	digitsum = digitsum + int(digit)
for digit in str(n):
	digitsum = digitsum + int(digit)
print(digitsum)


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())
s = int(input())
temp = 0
while s > temp * 10 + 9:
	temp = temp * 10
	temp += 9
s -= temp
s = str(s)
temp = str(temp)
ans = 0
for i in s:
	ans += int(i)
for i in temp:
	ans += int(i)
print(ans)


s = input()
st = ''
mina = min(1, int(s[0]) - 1)
st = str(mina)
for i in range(1, len(s)):
	st += '9'
st = int(st)
num = int(s) - st
ans = 0
while st:
	ans += st % 10
	st //= 10
while num:
	ans += num % 10
	num //= 10
print(ans)


a = input()
b = int(a[0]) * pow(10, len(a) - 1) - 1
a = int(a)
c = a - b
sum0 = 0
while b != 0 or c != 0:
	sum0 += b % 10 + c % 10
	b = b // 10
	c = c // 10
print(sum0)


def sumdigit(n):
	s = 0
	while n != 0:
		s += n % 10
		n = n // 10
	return s
n = int(input())
if n <= 9:
	print(n)
	exit()
num = 0
while num * 10 + 9 < n:
	num = num * 10 + 9
other = n - num
ans = 0
ans += sumdigit(other)
ans += sumdigit(num)
print(ans)


n = input()
if len(n) == 1:
	print(n)
	exit()
if n[0] == '1':
	a = int('9' * (len(n) - 1))
else:
	a = int(chr(ord(n[0]) - 1) + '9' * (len(n) - 1))
b = int(n) - a
res = 0
for i in str(a):
	res += int(i)
for i in str(b):
	res += int(i)
print(res)


def S(x):
	return sum(map(int, list(str(x))))
n = int(input())
t = len(str(n))
if t > 1:
	a = int('9' * (t - 1))
else:
	a = n
print(S(a) + S(n - a))


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

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

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]

def dig_total(s):
	return sum([int(x) for x in str(s)])
number = read_str()
lens = len(number)
ans1 = int(number[0]) * 10 ** (lens - 1) - 1
ans2 = int(number) - ans1
print(dig_total(ans1) + dig_total(ans2))


def digsum(n):
	return sum(map(int, str(n)))
A = int(input())
n = A // 2
s = str(n)
s = s[0] + '9' * len(s[1:])
print(digsum(int(s)) + digsum(A - int(s)))


def sod(p):
	sum = 0
	while p != 0:
		sum += p % 10
		p = p // 10
	return sum
n = input()
a = [int(x) for x in list(n)]
b = a[:]
b[0] = a[0] - 1
for i in range(1, len(a)):
	b[i] = 9
num1 = int(n)
num2 = 0
for i in range(len(b)):
	num2 = num2 * 10 + b[i]
print(sod(num1 - num2) + sod(num2))


n = int(input(''))
basamak = 0
if n < 10:
	print(n)
else:
	n1 = n
	toplam = 0
	while n1 > 0:
		rakam = int(n1 % 10)
		toplam = toplam + 1
		n1 = int(n1 / 10)
	basamak = toplam - 1
	sayi2 = 10 ** basamak - 1
	n = n - sayi2
	toplami = 0
	while n > 0:
		rakam = int(n % 10)
		toplami = toplami + rakam
		n = int(n / 10)
	toplami = toplami + basamak * 9
	print(toplami)


s = input()
p = ''
for i in range(len(s) - 1):
	p = p + '9'
try:
	q = str(int(s) - int(p))
	c = 0
	for i in q:
		c = c + int(i)
	print(c + 9 * (len(s) - 1))
except:
	print(s)


import sys

def S(n):
	if n < 0:
		return -1
	return sum((int(c) for c in str(n)))

def main():
	n_s = sys.stdin.readline().rstrip()
	n = int(n_s)
	if len(n_s) == 1:
		print(n)
		return
	a = int('9' * (len(n_s) - 1))
	b = n - a
	print(S(a) + S(b))
main()


n = int(input())
a = int(str(n)[0])
s = len(str(n)) - 1
x1 = a * 10 ** s - 1
x2 = n - x1

def s(x):
	return sum((int(d) for d in str(x)))
print(s(x1) + s(x2))


def s(d):
	return sum([int(i) for i in d])

def test(d):
	if int(d) < 10:
		print(d)
		return None
	a = int('9' * (len(d) - 1))
	print(s(str(int(d) - a)) + s(str(a)))
test(input())


def S(x):
	return sum(map(int, str(x)))
n = input()
len_n = len(n)
if len_n == 1:
	print(n)
	exit()
a = '9' * (len_n - 1)
b = int(n) - int(a)
print(S(a) + S(b))


n = list(map(int, list(input())))
output = 0
while len(n) > 0 and n[-1] == 9:
	output += 9
	del n[-1]
if len(n) >= 2:
	output += n[0] - 1 + n[-1] + 10
	n.remove(n[0])
	n.remove(n[-1])
	for i in n:
		output += i + 9
	print(output)
else:
	output += sum(n)
	print(output)


c = int(input())
k1 = (c // 2 // 10 ** (len(list(str(c // 2))) - 1) + 1) * 10 ** (len(list(str(c // 2))) - 1) - 1
k2 = c - k1
k1 = list(map(int, str(k1)))
k2 = list(map(int, str(k2)))
print(sum(k1) + sum(k2))


def sumofdig(n):
	sum1 = 0
	while n != 0:
		sum1 += n % 10
		n //= 10
	return sum1
n = input()
if len(n) == 1:
	print(n)
	exit()
a = '9' * (len(n) - 1)
sum1 = sumofdig(int(a)) + sumofdig(int(n) - int(a))
print(sum1)


a = input()
if int(a) > 9:
	b = '9' * (len(a) - 1)
	a = int(a) - int(b)
	s = str(a)
	q = sum(map(int, s)) + sum(map(int, b))
	print(q)
else:
	print(a)


n = input()
if len(n) == 1:
	print(n)
	exit()
a = (len(n) - 1) * '9'
b = str(int(n) - int(a))
print(sum([int(i) for i in list(a)]) + sum([int(i) for i in list(b)]))


def sumd(x):
	d = 0
	while x:
		d += x % 10
		x /= 10
		x = int(x)
	return d
n = int(input())

def contains0(x):
	while x:
		if x % 10 == 0:
			return True
		x /= 10
		x = int(x)
	return False

def solve(n):
	if n <= 10:
		return n
	x = 9
	while 10 * x + 9 < n:
		x = 10 * x + 9
	y = n - x
	return sumd(x) + sumd(y)
print(solve(n))


def sum_dig(n):
	return sum(map(int, str(n)))
n = int(input())
a = 9
while a < n:
	a = 10 * a + 9
a //= 10
print(sum_dig(a) + sum_dig(n - a))


def sumnum(x):
	z = str(x)
	l = len(z)
	d = 0
	m = 0
	for i in range(l):
		m = int(z[i])
		d += m
	return d
n = int(input())
f = 9
c = True
i = 1
if n < 9:
	maks = n
else:
	while c:
		if n >= f:
			f += 9 * 10 ** i
			i += 1
		else:
			c = False
	f -= 9 * 10 ** (i - 1)
	maks = sumnum(f) + sumnum(n - f)
print(maks)


n = int(input())
ans = 0
while n > 9:
	n -= 9
	ans += 9 + n % 10
	n = n // 10
print(ans + n)


def sumd(n):
	s = 0
	while n:
		s += n % 10
		n = n // 10
	return s
l = [9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, 9999999999, 99999999999, 999999999999, 9999999999999]
n = int(input())
i = 0
if n <= 9:
	print(n)
else:
	while i < 12 and l[i + 1] <= n:
		i += 1
	rem = n - l[i]
	print(9 * (i + 1) + sumd(rem))


n = int(input())
a = 9
while n > a:
	a = 10 * a + 9
a //= 10
b = n - a
print(sum(map(int, str(a))) + sum(map(int, str(b))))


import math
n = int(input())
if n < 10:
	print(n)
else:
	ss = str(n)
	rr = '9' * (len(ss) - 1)
	xx = int(rr)
	yy = n - xx
	s1 = str(xx)
	s2 = str(yy)
	s = 0
	for i in s1:
		s += int(i)
	for j in s2:
		s += int(j)
	print(s)


(n, ans, kf) = (int(input()), 0, 0)
while n % 10 == 9:
	ans += 9
	n //= 10
if n == 0:
	print(int(ans))
	exit(0)
while n > 0:
	ans += n % 10
	kf += 1
	n //= 10
print(ans + (kf - 1) * 9)


w = int(input())
n = list(map(int, list(str(w))))
n[0] -= 1
for i in range(1, len(n)):
	n[i] = 9
n = list(map(str, n))
s = int(''.join(n))
b = w - s
a = list(map(int, list(str(s))))
b = list(map(int, list(str(b))))
print(sum(a) + sum(b))


a = [9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, 9999999999, 99999999999, 999999999999]
n = int(input())
vt = 0
if n <= 9:
	print(n)
else:
	for i in a:
		if i <= n:
			vt += 1
		else:
			break
	m = n - a[vt - 1]
	ans = 0
	while m > 0:
		ans += int(m % 10)
		m /= 10
	while a[vt - 1] > 0:
		ans += int(a[vt - 1] % 10)
		a[vt - 1] /= 10
	print(ans)


from sys import stdin
input = lambda : stdin.readline().rstrip('\r\n')

def su(n):
	c = 0
	while n:
		c += n % 10
		n //= 10
	return c
n = int(input())
if n < 10:
	print(n)
else:
	t = str(n)
	a = int(str(int(t[0]) - 1) + '9' * (len(t) - 1))
	b = n - a
	print(su(a) + su(b))


n = int(input())
s = n // 10 ** (len(str(n)) - 1)
a = str(s - 1) + str('9' * (len(str(n)) - 1))
b = n - int(a)
n = 0
for i in str(a):
	n += int(i)
a = n
n = 0
for i in str(b):
	n += int(i)
print(a + n)


n = input()
if len(n) == 1:
	print(n)
else:
	t = 9 * (len(n) - 1)
	y = sum(map(int, list(str(int(n) - int('9' * (len(n) - 1))))))
	print(t + y)


def find(n):
	cnt = 0
	if n < 10:
		return cnt + n
	cnt += n % 10 + 10
	if n % 10 == 9:
		cnt -= 10
		return cnt + find(n // 10)
	return cnt + find(n // 10 - 1)
print(find(int(input())))


n = input()
ln = len(n)
if ln > 1:
	k = ['9'] * (ln - 1)
	f = int(''.join(k))
	f2 = int(n) - f
	ans = 9 * len(k)
	f2 = str(f2)
	for i in f2:
		ans += int(i)
	print(ans)
else:
	print(n)


def sum_of_num(x):
	x = str(x)
	ans = 0
	for i in range(len(x)):
		ans += int(x[i])
	return ans
n = int(input())
if n < 10:
	print(n)
	exit()
print(sum_of_num(n - int((len(str(n)) - 1) * '9')) + sum_of_num(int((len(str(n)) - 1) * '9')))


n = int(input())
c = 0
a = n
while a > 0:
	a //= 10
	c += 1
if c == 1:
	print(n)
else:
	nines = 0
	for i in range(c - 1):
		nines = nines * 10 + 9
	n -= nines
	ans = 0
	while n > 0:
		ans += n % 10
		n //= 10
	print(ans + 9 * (c - 1))


def sum1(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s
n = int(input())
e = str(n)
e = str(int(e[0]) - 1) + '9' * (len(e) - 1)
e = int(e)
print(sum1(e) + sum1(n - e))


def next(kk):
	return kk * 10 + 9
n = int(input())
cur = 0
while next(cur) <= n:
	cur = next(cur)
a = cur
b = n - cur
k = a
nn = 0
while k > 0:
	nn += k % 10
	k = int(k // 10)
ans = nn
k = b
nn = 0
while k > 0:
	nn += k % 10
	k = int(k // 10)
ans += nn
print(ans)


n = int(input())
nStr = str(n)
nMAX = int(nStr[0]) * 10 ** (len(nStr) - 1) - 1
nMIN = n - nMAX
res1 = sum((int(i) for i in str(nMAX)))
res2 = sum((int(i) for i in str(nMIN)))
print(res1 + res2)


n = int(input())
if n < 10:
	print(n)
	exit()
a = int('9' * (len(str(n)) - 1))
b = n - a
ans = 0
while a > 0:
	ans += a % 10
	a = a // 10
while b > 0:
	ans += b % 10
	b = b // 10
print(ans)


from math import *
a = [int(i) for i in input()]
ans = 0
carry = 0
for i in range(len(a) - 1, -1, -1):
	if i == 0:
		ans += a[i] - carry
	elif a[i] == 9 and (not carry):
		ans += 9
	else:
		ans += 10 + a[i] - carry
		carry = 1
print(ans)


def find_dig_sum(n):
	summ = 0
	while n > 0:
		summ += n % 10
		n //= 10
	return summ
t = int(input())
temp = t
digits = 0
while t > 0:
	first = t % 10
	t //= 10
	digits += 1
a = [0] * digits
for i in range(len(a)):
	if i == 0:
		a[0] = first - 1
	else:
		a[i] = 9
a = ''.join(map(str, a))
a = int(a)
b = temp - a
print(find_dig_sum(a) + find_dig_sum(b))


s = input()
l = len(s)
if l < 2:
	print(s)
else:
	s1 = '9' * (l - 1)
	s2 = str(int(s) - int(s1))
	print(sum(map(lambda x: int(x), s1 + s2)))


def count_sum(num):
	ans = 0
	while num > 0:
		digit = num % 10
		ans += digit
		num /= 10
		num = int(num)
	return ans
num_str = input()
target_nos = int('0' + '9' * (len(str(num_str)) - 1))
other_nos = int(num_str) - target_nos
ans = count_sum(target_nos) + count_sum(other_nos)
print(ans)


n = int(input())
lenN = len(str(n))
strA = (lenN - 1) * '9' or '0'
strB = str(n - int(strA))
sumA = sum([int(ch) for ch in strA])
sumB = sum([int(ch) for ch in strB])
print(sumA + sumB)


x = input().split(' ')
n = eval(x[0])
i = 0
while n // 10 ** i != 0:
	i += 1
if i == 1:
	print(n)
else:
	s = 0
	temp = 0
	for j in range(i):
		if j == 0:
			if n % 10 == 9:
				s += 9
			else:
				s += 10 + n % 10
				temp = 1
		elif j == i - 1:
			s += n - temp
		elif n % 10 == 0:
			s += 10 - temp
			if temp == 0:
				temp = 1
		elif n % 10 == 9 and temp == 0:
			s += 9
		else:
			s += 10 + n % 10 - temp
			temp = 1
		n = (n - n % 10) / 10
	print(int(s))


def getSum(n):
	sum = 0
	while n != 0:
		sum = sum + int(n % 10)
		n = int(n / 10)
	return sum
n = int(input())
if n <= 9:
	print(n)
else:
	x = 0
	while x * 10 + 9 <= n:
		x = x * 10 + 9
	print(getSum(x) + getSum(n - x))


n = input()
if len(n) == 1:
	print(int(n))
else:
	a = ''
	if n[0] != '1':
		a += chr(ord(n[0]) - 1)
	a += '9' * (len(n) - 1)
	b = str(int(n) - int(a))
	print(sum(map(int, list(a) + list(b))))


n = int(input())
x = 0
while True:
	if x * 10 + 9 <= n:
		x = x * 10 + 9
	else:
		break
y = n - x
s = 0
while x:
	s += x % 10
	x //= 10
while y:
	s += y % 10
	y //= 10
print(s)


def S(a):
	return sum([int(x) for x in str(a)])

def suman(a):
	res = 0
	suma = []
	for i in range((a + 1) / 2):
		(x, y) = (i, abs(a - i))
		ans = S(x) + S(y)
		if res < ans:
			res = ans
			suma = [[x, y]]
		elif res == ans:
			suma.append([x, y])
	print(res)
	for i in suma:
		print(i)
kumar = input()
if len(kumar) == 1:
	print(kumar)
else:
	n = len(kumar)
	a = int(str(int(kumar[0]) - 1) + '9' * (n - 1))
	b = int(kumar) - a
	print(S(a) + S(b))


def s(x):
	return sum(map(int, list(str(x))))
n = input()
a = 10 ** (len(n) - 1) - 1
print(s(a) + s(int(n) - a))


s = input()
ANS = 0
for i in range(len(s) - 1):
	ANS = ANS * 10 + 9
NUMMM = 0
for i in range(10):
	NUMMM += str(int(s) - ANS).count('{0}'.format(i)) * i
print((len(s) - 1) * 9 + NUMMM)


def S(n):
	n = str(n)
	ans = 0
	for num in n:
		ans += int(num)
	return ans
n = int(input())
_n = [int(x) for x in str(n)]
if n <= 10:
	print(n)
else:
	fill = len(_n)
	a = str(_n[0] - 1) + '9' * (fill - 1)
	b = n - int(a)
	print(S(a) + S(b))


def sums(x):
	s = 0
	while x > 0:
		s += x % 10
		x = int(x / 10)
	return s
n = input()
x = int(n)
half = int(x / 2)
half1 = str(half)
v = str()
v += half1[0]
for i in range(1, len(half1)):
	v += '9'
v = int(v)
half = x - v
s1 = sums(v)
s2 = sums(half)
print(s1 + s2)


n = input()
if int(n) <= 10:
	print(n)
else:
	nine = ''
	nine += (len(n) - 1) * '9'
	ans = int(n) - int(nine)
	ar1 = [int(i) for i in nine]
	ar2 = [int(i) for i in str(ans)]
	print(sum(ar1) + sum(ar2))


def generate_9_repetition_less_than(n):
	s = f'{n}'
	if len(s) < 2:
		return 0
	return int('9' * (len(s) - 1))

def S(n):
	return sum((int(x) for x in str(n)))
n = int(input())
n1 = generate_9_repetition_less_than(n)
n2 = n - n1
print(S(n1) + S(n2))


n = int(input())
num = str(n)
total = n
if n > 9:
	a = '9' * (len(num) - 1)
	a2 = int(a)
	b = n - a2
	b = str(b)
	total = 0
	for dig in a:
		total += int(dig)
	for dig in b:
		total += int(dig)
print(total)


n = int(input())
d1 = 0
d2 = 0
res = 0
if len(str(n)) < 2:
	print(n)
else:
	m = len(str(n))
	n2 = int('9' * (m - 1))
	n1 = n - n2
	for c in str(n2):
		res += int(c)
	for c in str(n1):
		res += int(c)
	print(res)


def summ(n):
	n = str(n)
	ans = 0
	for i in n:
		ans += int(i)
	return ans
n = int(input())
ans = 9
while ans < n:
	ans *= 10
	ans += 9
ans -= 9
ans //= 10
print(summ(ans) + summ(n - ans))


n = input()
l = len(n)
i1 = str(int(n[0]) - 1) + '9' * (l - 1)
i2 = str(int(n) - int(i1))
s = 0
for i in str(i1):
	s += int(i)
for i in str(i2):
	s += int(i)
print(s)


def digSum(x):
	s = 0
	while x > 0:
		s += x % 10
		x //= 10
	return s
ans = 0
n = int(input())
k = 0
while k <= n:
	ans = max(ans, digSum(k) + digSum(n - k))
	k = k * 10 + 9
print(ans)


n = int(input())

def sumDigits(x):
	if x < 10:
		return x
	res = 0
	while x != 0:
		res += x % 10
		x = x // 10
	return res

def Tot():
	ch = str(n)
	power = pow(10, len(ch) - 1)
	nb = n // power * power - 1
	print(sumDigits(nb) + sumDigits(n - nb))
Tot()


s = str(input())
if len(s) == 1:
	print(s)
	exit()
flag = False
summ = 0
chek = 0
is9 = True
for i in range(1, len(s)):
	chek = 1
	if int(s[-i]) == 9 and is9 == True:
		summ -= 10
		chek = 0
	else:
		is9 = False
	a = 10 + int(s[-i]) - chek
	flag = False
	chek = 1
	n = a // 2
	nn = a - n
	summ += n + nn
summ += int(s[0])
print(summ)


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = 1
for tt in range(t):
	s = str(input())
	n = int(s)
	k = ''
	for i in range(len(s) - 1):
		k += '9'
	if k == '':
		k = 0
	else:
		k = int(k)
	n -= k
	n = str(n)
	ans = 0
	k = str(k)
	for c in k:
		ans += int(c)
	for c in n:
		ans += int(c)
	print(ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


from math import log10
n = int(input())

def sumsum(i, j):
	ii = list(map(int, list(str(i))))
	jj = list(map(int, list(str(j))))
	return sum(ii) + sum(jj)

def brute_force(n):
	max_sum = 0
	for i in range(n + 1):
		j = n - i
		cur_sum = sumsum(i, j)
		if cur_sum > max_sum:
			max_sum = cur_sum
	return max_sum

def for_clever(n):
	if n == 0:
		return 0
	n_order = int(log10(n))
	cand1 = 10 ** n_order - 1
	cand2 = n - cand1
	return sumsum(cand1, cand2)
print(for_clever(n))


n = int(input())
s = 0
while n > 0:
	r = n % 10
	if r < 9 and n // 10 > 0:
		s += 10 + r
		n -= 10 + r
	else:
		s += r
		n -= r
	n = n // 10
print(s)


def main():
	n = int(input())
	print(solver(n))

def countOfDigits(n):
	count = 0
	while n > 0:
		n //= 10
		count += 1
	return count

def sumOfDigits(n):
	total = 0
	while n > 0:
		total += n % 10
		n //= 10
	return total

def getlastDthDigit(n, d):
	return n % 10 ** d // 10 ** (d - 1)

def solver(n):
	digitSum = sumOfDigits(n)
	digitCount = countOfDigits(n)
	ninescount = digitCount - 1
	for i in range(1, digitCount):
		if getlastDthDigit(n, i) != 9:
			ninescount = i - 1
			break
	return 10 * (digitCount - 1) + digitSum - digitCount + 1 - 9 * ninescount
main()


n = input()
if int(n) <= 9:
	print(n)
else:
	summ = 0
	dig = len(n)
	last = int(n[0]) - 1
	summ = last + (dig - 1) * 9
	num = last * int(str(1) + '0' * (dig - 1)) + int('9' * (dig - 1))
	resid = int(n) - num
	hege = list(str(resid))
	for i in hege:
		summ += int(i)
	print(summ)


def f(a):
	s = 0
	while a != 0:
		s += a % 10
		a //= 10
	return s
a = int(input())
x = 0
while x < a:
	x *= 10
	x += 9
x //= 10
y = a - x
print(f(x) + f(y))


def cal(i):
	now = 0
	temp = str(i)
	for x in temp:
		now = now + int(x)
	return now
num = int(input())
if num <= 9:
	print(num)
else:
	num1 = ''
	for i in range(1, len(str(num))):
		num1 = num1 + '9'
	num1 = int(num1)
	print(cal(num1) + cal(num - num1))


def s(k):
	su = 0
	for f in str(k):
		su += int(f)
	return su
n = int(input())
if n <= 9:
	print(n)
else:
	ans = 9
	st = '9'
	for j in range(0, 13):
		for i in range(9, -1, -1):
			y = int(str(i) + st)
			if y <= n:
				st = str(i) + st
				ans += i
				break
	print(s(n - int(st)) + ans)


def f(x):
	m = 0
	while 1:
		if m < x:
			m *= 10
			m += 9
		else:
			break
	return m // 10

def sm(x):
	m = 0
	while x > 0:
		m += x % 10
		x //= 10
	return m
x = int(input())
k = f(x)
print(sm(k) + sm(x - k))


import math
num = int(input())
if num < 10:
	print(num)
else:
	a = int(str(num)[1:]) + 1
	b = num - a

	def calc(value):
		lst = list(map(int, list(str(value))))
		return sum(lst)
	print(calc(a) + calc(b))


n = int(input())
n = str(n)
b = 10 ** (len(n) - 1) - 1
n = int(n)
c = n - b
b = list(str(b))
c = list(str(c))
d = 0
for i in range(len(b)):
	d += int(b[i])
for i in range(len(c)):
	d += int(c[i])
print(d)


n = input()
if len(n) == 1:
	print(n)
	exit()
first = int(n[0])
x = int(str(first - 1) + '9' * (len(n) - 1))
y = int(n) - x
sum_ = 0
while x:
	sum_ += x % 10
	x = x // 10
while y:
	sum_ += y % 10
	y = y // 10
print(sum_)


n = int(input())

def S(x):
	if x == 0:
		return 0
	else:
		return x % 10 + S(x // 10)
x = 9
while x < n:
	x = 10 * x + 9
x = x // 10
print(S(x) + S(n - x))


n = int(input())
if n <= 9:
	print(n)
else:
	nineth = 0
	while True:
		nineth += 1
		if n - int('9' * (nineth + 1)) <= 0:
			break
	decrement = int('9' * nineth)
	print(sum(map(int, list(''.join(map(str, [decrement, n - decrement]))))))


st = input()
ns = str() + str(int(st[0]) - 1)
for i in range(len(st) - 1):
	ns += '9'
pnt = int(ns)
nint = int(st) - pnt
ans = 0
while pnt:
	ans += pnt % 10
	pnt //= 10
while nint:
	ans += nint % 10
	nint //= 10
print(ans)


n = input()
if len(n) == 1:
	print(n)
else:
	if len([_ for _ in n if _ != '9']) == 0:
		(a, b) = (n, '0')
	else:
		a = '9' * (len(n) - 1)
		b = str(int(n) - int(a))
	s = sum([int(_) for _ in a]) + sum([int(_) for _ in b])
	print(s)


import math
n = input()
l = len(n)
n = int(n)
ff = n % 10 ** (l - 1) + 1
bb = n - ff

def s(n):
	ss = 0
	while n:
		ss += n % 10
		n //= 10
	return ss
print(s(bb) + s(ff))


def f(n):
	return n % 10

def r(n):
	if f(n) == n:
		return n
	elif f(n) == 9:
		return r(n // 10) + f(n)
	else:
		return r(n // 10 - 1) + 10 + f(n)
n = int(input())
print(r(n))


n = input()
if len(n) == 1:
	print(n)
	exit()
num1 = '9' * (len(n) - 1)
print(9 * len(num1) + sum(map(int, str(int(n) - int(num1)))))


s = input()
n = int(s)
if n < 10:
	print(n)
else:
	a = ''
	if n // 10 ** (len(s) - 1) > 1:
		a += str(n // 10 ** (len(s) - 1) - 1)
	a += (len(s) - 1) * '9'
	b = n - int(a)
	x = 0
	for c in a:
		x += int(c)
	for c in str(b):
		x += int(c)
	print(x)


def digit_sum(num):
	res = 0
	while num != 0:
		res += num % 10
		num //= 10
	return res

def main():
	n = int(input())
	a = 0
	while a * 10 + 9 <= n:
		a = a * 10 + 9
	print(digit_sum(a) + digit_sum(n - a))
main()


a = int(input())
c = 0
while a > 0:
	if a % 10 < 9 and a > 9:
		t = 10 + a % 10
	else:
		t = a % 10
	c += t
	a -= t
	a //= 10
print(c)


def summation(number):
	result = 0
	while number > 0:
		result += number % 10
		number //= 10
	return result

def max_sum(numb):
	if numb < 9:
		return numb
	m = 9
	while 10 * m + 9 <= numb:
		m = m * 10 + 9
	return summation(numb - m) + summation(m)
print(max_sum(int(input())))


n = int(input())
N = str(n)
if len(N) == 1:
	print(n)
else:
	l = len(N) - 1
	k = int('9' * l)
	diff = n - k
	D = str(diff)
	K = str(k)
	sumu = 0
	for i in range(0, len(D)):
		sumu = sumu + int(D[i])
	for i in range(0, len(K)):
		sumu = sumu + int(K[i])
	print(sumu)


n = input()
ans = 0
for i in range(len(n) - 1):
	ans = ans * 10 + 9
num = 0
for i in range(10):
	num += str(int(n) - ans).count('{0}'.format(i)) * i
print((len(n) - 1) * 9 + num)


def digit_sum(x):
	x = str(x)
	r = 0
	for d in x:
		r += int(d)
	return r

def solve():
	n = int(input())
	if n < 10:
		print(n)
		return
	num = n - n % 10 ** (len(str(n)) - 1) - 1
	a = num
	b = n - a
	best = digit_sum(a) + digit_sum(b)
	for i in range(min(a, 1000)):
		a -= 1
		b += 1
		cur = digit_sum(a) + digit_sum(b)
		if cur > best:
			best = cur
	print(best)
solve()


def C(n):
	ans = 0
	while n != 0:
		ans += 1
		n //= 10
	return ans

def S(n):
	ans = 0
	while n > 0:
		ans += n % 10
		n //= 10
	return ans
n = int(input())
d = C(n)
num1 = 10 ** (d - 1) - 1
num2 = n - num1
print(S(num1) + S(num2))


def s(x):
	return sum(map(int, str(x)))
n = int(input())
print(s(n) + 9 * max(0, len(str(n).rstrip('9')) - 1))


n = input()
number_length = len(n)
n = int(n)
if n < 10:
	print(n)
	exit(0)
mod = n % pow(10, number_length - 1)
a1 = n - mod - 1
a2 = mod + 1
a1 = list(str(a1))
a2 = list(str(a2))
a1.extend(a2)
answer = 0
for a in a1:
	if a != '-':
		answer += int(a)
print(answer)


def getsum(num):
	sum = 0
	while num != 0:
		sum += num % 10
		num //= 10
	return sum

def main():
	num = int(input())
	if num < 10:
		print(num)
	else:
		_st = int((len(str(num)) - 1) * '9')
		_nd = num - _st
		print(getsum(_st) + getsum(_nd))
main()


def digit_sum(x):
	ans = 0
	while x > 0:
		ans += x % 10
		x = x // 10
	return ans

def digit_count(x):
	ans = 0
	while x > 0:
		ans += 1
		x = x // 10
	return ans
n = int(input())
(a, b) = (0, 0)
ans = 0
if n <= 18:
	print(n)
else:
	new_num = 1
	for i in range(digit_count(n) - 1):
		new_num = new_num * 10 + 9
	if new_num > n:
		new_num = 9
		for i in range(digit_count(n) - 2):
			new_num = new_num * 10 + 9
	print(digit_sum(new_num) + digit_sum(n - new_num))


n = int(input())
k = len(str(n))
a = 0
while k > 1:
	a = a * 10 + 9
	k -= 1
print(sum((int(x) for x in str(a))) + sum((int(x) for x in str(n - a))))


def f(a, b):
	res = 0
	for i in a:
		res += int(i)
	for i in b:
		res += int(i)
	return res
n = int(input())
if n < 18:
	print(n)
	exit()
elif n < 100:
	t = 0
	a = n // 10
	if n % 10 != 0:
		t = a * 10 - 1
	else:
		t = n - 1
	v = n - t
	res = f(str(t), str(v))
	print(res)
else:
	k = str(n)
	t = '9' * (len(k) - 1)
	t = int(t)
	v = n - t
	print(f(str(v), str(t)))


def S(x):
	res = 0
	while x != 0:
		res += x % 10
		x //= 10
	return res
n = input()
num = int(n[0]) - 1
a = num
for i in range(len(n) - 1):
	a = a * 10 + 9
n = int(n)
b = n - a
print(S(a) + S(b))


n = int(input())
n1 = 0
cnt = 0
while n1 <= n:
	x = n1
	cnt += 1
	n1 = n1 * 10 + 9
cnt -= 1
n1 = x
s1 = 9 * cnt
n2 = n - n1
s2 = 0
while n2:
	rem = n2 % 10
	s2 += rem
	n2 //= 10
print(s1 + s2)


m = n = int(input())
a = 0
p = 1
while n > 0:
	d = 9
	while n - d < 0:
		d -= 1
	n -= d
	a = a + p * d
	p = p * 10
	n //= 10
b = m - a
s = sum((int(x) for x in str(a) + str(b)))
print(s)


def countdig(n):
	ans = 0
	while n != 0:
		ans += 1
		n //= 10
	return ans

def summ(n):
	ans = 0
	while n > 0:
		ans += n % 10
		n //= 10
	return ans
n = int(input())
d = countdig(n)
num1 = 10 ** (d - 1) - 1
num2 = n - num1
print(summ(num1) + summ(num2))


def digitsum(n):
	r = 0
	while n:
		r += n % 10
		n //= 10
	return r

def solve(n):
	x = 9
	s = 0
	r = 0
	while x <= n:
		y = n - x
		r = max(r, digitsum(x) + digitsum(y))
		x = x * 10 + 9
	t = n // 2
	q = n - t
	return max(r, digitsum(t) + digitsum(q))
n = int(input())
print(solve(n))


a = int(input())
v = 9
if a > 0:
	while v < a:
		v = v * 10 + 9
v //= 10
s = a - v
print(sum([int(x) for x in str(v)]) + sum([int(x) for x in str(s)]))


n = input()
k = len(n) - 1
print(sum(map(int, str(int(n) - int('0' + '9' * k)))) + 9 * k)


def S(x):
	ss = 0
	while x > 0:
		ss += x % 10
		x = x // 10
	return ss
n = input()
s = ''
s = s + '9' * (len(n) - 1)
if n[0] == '9':
	if int('9' + s) > int(n):
		s = chr(ord(n[0]) - 1) + s
	else:
		s = '9' + s
else:
	s = chr(ord(n[0]) - 1) + s
print(S(int(s)) + S(int(n) - int(s)))


n = int(input())
h = n
k = len(str(n)) - 1
y = str(n)[0]
a = int(str(int(y) - 1) + k * '9')
b = list(map(int, list(str(h - a))))
a = list(map(int, list(str(a))))
print(sum(a) + sum(b))


def sum_digit(a):
	k = a
	dem = 0
	while k > 0:
		x = k % 10
		dem += x
		k = int(k / 10)
	return dem
ch = input()
n = int(ch)
ch = str(n)
if len(ch) > 1:
	n1 = str(int(ch[0]) - 1)
	if n1 == '0':
		n1 = ''
	for i in range(len(ch) - 1):
		n1 += '9'
	x = int(n1)
	y = n - x
	print(sum_digit(x) + sum_digit(y))
else:
	print(n)


n = input()
if len(n) == 1:
	print(n)
	exit()
else:
	k = '9' * (len(n) - 1)
	s = 9 * (len(n) - 1)
	p = int(n) - int(k)
	z = str(p)
	for i in z:
		s += int(i)
	print(s)


def dig(x):
	sumi = 0
	while x != 0:
		sumi = sumi + x % 10
		x = x // 10
	return sumi
b = input()
n = int(b)
l = len(b)
if l > 1:
	c = (l - 1) * '9'
	print(dig(int(c)) + dig(n - int(c)))
else:
	print(n)


from functools import reduce
n = input()
l = len(n)
x = str(int(n[0]) - 1) + '9' * (l - 1)
t = x + str(int(n) - int(x))
print(reduce(lambda x, y: x + y, [int(i) for i in t]))


n = input()
m = len(n)
if m > 1:
	s1 = ''.join(['9'] * (m - 1))
	s2 = int(n) - int(s1)
	ans = 9 * (m - 1) + sum([int(x) for x in list(str(s2))])
	print(ans)
else:
	print(n)


n = input()
x = pow(10, len(n) - 1) - 1
s = lambda x: sum((int(c) for c in str(x)))
print(s(int(n) - x) + s(x))


def d(x):
	c = 0
	while x > 0:
		c += x % 10
		x //= 10
	return c
n = int(input())
ans = 0
if n <= 10:
	ans = n
else:
	temp = 9
	while temp * 10 + 9 < n:
		temp *= 10
		temp += 9
	b = n - temp
	ans += d(b)
	ans += d(temp)
print(ans)


n = int(input())
if n < 10:
	print(n)
else:
	s = len(str(n)) - 1
	x = n // 10 ** s
	x = x * 10 ** s - 1
	y = n - x
	x = list(map(int, list(str(x))))
	y = list(map(int, list(str(y))))
	print(sum(x) + sum(y))


import math

def findLargestSum(n):
	digits = digitsFromNumber(n)
	if len(digits) == 1:
		print(n)
	else:
		size = len(digits)
		numberWithNines = 0
		i = 0
		while i < size - 1:
			numberWithNines += 9 * math.pow(10, i)
			i += 1
		firstDigit = int(digits[0]) - 1
		numberWithNines += firstDigit * math.pow(10, size - 1)
		numberWithNines = int(numberWithNines)
		rest = n - numberWithNines
		print(sum(digitsFromNumber(numberWithNines)) + sum(digitsFromNumber(rest)))

def digitsFromNumber(number):
	listOfDigitsFromN = list(map(int, list(str(number))))
	return listOfDigitsFromN
n = int(input())
findLargestSum(n)


n = input()
final = 0
if len(n) > 2:
	if n[0] != '1':
		ln = len(n)
		maxArr = ['0']
		maxArr[0] = str(int(n[0]) - 1)
		for i in range(len(n) - 1):
			maxArr.append(9)
		max = int(''.join((str(e) for e in maxArr)))
		min = str(int(n) - max)
		for i in maxArr:
			final += int(i)
		for i in range(len(min)):
			final += int(min[i])
		print(final)
	else:
		ln = len(n)
		maxArr = ['9']
		for i in range(len(n) - 2):
			maxArr.append(9)
		max = int(''.join((str(e) for e in maxArr)))
		min = str(int(n) - max)
		for i in maxArr:
			final += int(i)
		for i in range(len(min)):
			final += int(min[i])
		print(final)
else:
	n = int(n)
	final = []

	def sum_digits(digit):
		return sum((int(x) for x in digit if x.isdigit()))
	for i in range(int(n / 2) + 1):
		digit = str(i) + str(n - i)
		final.append(sum_digits(digit))
	max = int(max(final))
	print(max)


n = input()
t = n
c = len(n)
if c > 1:
	t = int(n[0]) - 1
	a = str(t)
	for i in range(0, c - 1):
		a += '9'
		t += 9
	b = str(int(n) - int(a))
	for i in range(0, len(b)):
		t += int(b[i])
print(t)


n = input()
l = len(n) - 1
if l == 0:
	print(n)
else:
	a = str(int(n) - int('9' * l))
	ans = 9 * l
	for i in a:
		ans += int(i)
	print(ans)


n = int(input())
s = ''
while int(s + '9') <= n:
	s += '9'
if not s:
	s = '0'
print(sum((int(i) for i in s)) + sum((int(i) for i in str(n - int(s)))))


n = int(input())
if n < 10:
	print(n)
	exit(0)
a = n - int(str(n)[1:]) - 1
b = n - a
a = [*map(int, str(a))]
b = [*map(int, str(b))]
print(sum(a) + sum(b))


x = int(input())
if x >= 10:
	split = x
	split = str(split)
	split = int((len(split) - 1) * '9')
	split = int(split)
	split2 = x - split
	split = str(split)
	split2 = str(split2)
	sum = 0
	for i in range(len(split)):
		sum += int(split[i])
	for i in range(len(split2)):
		sum += int(split2[i])
	print(sum)
else:
	print(x)


import math
y = [int(i) for i in input().split()]
n = y[0]

def sn(x):
	s = 0
	x = str(x)
	for i in range(len(x)):
		s += int(x[i])
	return s

def n9(x):
	x = len(str(x)) - 1
	return '9' * x
if len(str(n)) > 1:
	print(sn(n - int(n9(n))) + sn(int(n9(n))))
else:
	print(n)


n = int(input())
if n < 10:
	print(n)
	return
a = n - int(str(n)[1:]) - 1
b = n - a
a = [*map(int, str(a))]
b = [*map(int, str(b))]
print(sum(a) + sum(b))


n = input()
x = int(n[0])
a = str(x // 2) + '9' * (len(n) - 1)
b = str(int(n) - int(a))
a = list(map(int, a))
b = list(map(int, b))
print(sum(a) + sum(b))


n = int(input())
k = 0
while 10 ** k - 1 <= n:
	k += 1
k -= 1
a = 10 ** k - 1
b = n - a
a1 = list(str(a))
b1 = list(str(b))
for i in range(len(a1)):
	a1[i] = int(a1[i])
for i in range(len(b1)):
	b1[i] = int(b1[i])
num = 0
num += sum(a1)
num += sum(b1)
print(num)


n = int(input())

def get(a):
	return sum(map(int, str(a)))

def solve(n):
	cnt = len(str(n))
	if cnt == 1:
		return get(n)
	ret = get(n)
	for a in ['9' * (cnt - 1)]:
		ret = max(get(int(a)) + get(n - int(a)), ret)
	return ret
print(solve(n))


from math import *
n = int(input())
m = 10 ** floor(log10(n)) - 1
print(sum([int(i) for i in str(m)]) + sum([int(i) for i in str(n - m)]))


def sumOfString(numberStr):
	return sum(map(int, list(str(numberStr))))
value = int(input())
strLength = len(str(value))
if strLength > 1:
	firstHalf = int('9' * (strLength - 1))
else:
	firstHalf = value
print(sumOfString(firstHalf) + sumOfString(value - firstHalf))


from sys import stdin, stdout

def sum_digits(n):
	s = 0
	while n:
		s += n % 10
		n //= 10
	return s
N = int(input())
if N <= 9:
	print(N)
	quit()
base = 9
res = 0
while base <= N:
	d = N - base
	r = sum_digits(d) + sum_digits(base)
	res = max(res, r)
	base = base * 10 + 9
print(res)


n = int(input())
a = len(str(n)) - 1
print(sum(map(int, str(n - int('0' + '9' * a)))) + 9 * a)


n = int(input())

def getdigit(a):
	ans = 0
	while a:
		ans += a % 10
		a //= 10
	return ans

def solve(n):
	if n < 10:
		return n
	c = len(str(n))
	ans = (c - 1) * 9
	(a, b) = divmod(n, 10 ** (c - 1))
	return ans + getdigit(b + 1) + a - 1
print(solve(n))


n = int(input())

def suma(x):
	return sum(map(int, list(str(x))))
a = 0
while a * 10 + 9 <= n:
	a = a * 10 + 9
print(suma(a) + suma(n - a))


nstr = input()
n = int(nstr)
lenn = len(nstr)
ndu = int(nstr[-1])
if n < 10:
	avgnum = int(n / 2)
	if ndu % 2 != 0:
		a = avgnum
		b = avgnum + 1
	else:
		a = b = avgnum
elif int(nstr[:2]) <= 20:
	a = int('9' * (lenn - 1))
	b = n - a
else:
	a = int('1' + '9' * (lenn - 1))
	b = n - a
sumnum = 0
for ele in str(a):
	if ele == '.':
		break
	sumnum += int(ele)
for ele in str(b):
	if ele == '.':
		break
	sumnum += int(ele)
print(sumnum)


from math import log2
n = input()
maxs = 0
if int(n) < 10:
	print(n)
else:
	for i in range(2 ** (len(n) - 1)):
		tru = [int(j) for j in '0' * (len(n) - len(bin(i)) + 1) + bin(i)[2:]]
		s = int(n[0]) - tru[0]
		for j in range(1, len(tru) + 1):
			if j != 1 and n[-j] == '9' and tru[1 - j]:
				pass
			elif n[-j] == '9' and tru[-j]:
				s = 0
				break
			if j == 1:
				if tru[-1] == 0:
					s += int(n[-1])
				else:
					s += int(n[-1]) + 10
			else:
				if tru[1 - j]:
					c = int(n[-j]) - 1
				else:
					c = int(n[-j])
				if tru[-j]:
					s += 10 + c
				else:
					s += c
		if s > maxs:
			maxs = s
			maks = tru
	print(maxs)


s = input()
ans = ''
for i in range(len(s) - 1):
	ans += '9'
if int('1' + ans) < int(s):
	ans = '1' + ans
if len(ans) == 0:
	ans = '0'
ansInt = int(ans)
rest = int(s) - ansInt
restStr = str(rest)
finAns = 0
for i in ans:
	finAns += int(i)
for i in restStr:
	finAns += int(i)
print(finAns)


x = input()
x = x[len(x) - 1:0:-1] + x[0]
max = 0
goodboi = 0
for i in range(len(x)):
	if goodboi == 1 and i < len(x) - 1:
		max += int(x[i]) + 9
	elif i == len(x) - 1:
		max += int(x[i]) - goodboi
	elif int(x[i]) == 9:
		max += 9
	else:
		max += int(x[i]) + 10
		goodboi = 1
print(max)


n = int(input())

def solve(n):
	temp = -1
	if n <= 9:
		return n
	if n % 10 != 9:
		temp = solve(n // 10 - 1) + n % 10 + 10
	temp = max(temp, solve(n // 10) + n % 10)
	return temp
print(solve(n))


s = input()
n = len(s)
s1 = '0'
for i in range(0, n - 1):
	s1 = s1 + '9'
k1 = int(s1)
k2 = int(s)
k3 = k2 - k1
s2 = str(k3)
c = 0
for i in range(0, len(s2)):
	c = c + int(s2[i])
print(c + 9 * (n - 1))


def gets(n):
	sum = 0
	while n > 0:
		sum += n % 10
		n = n // 10
	return sum
n = input()
s = '9' * (len(n) - 1)
if len(s) == 0:
	s = '0'
print(gets(int(s)) + gets(int(n) - int(s)))


from math import log10, ceil

def sumdigs(n):
	return sum(map(int, str(n)))
n = int(input())
tens = int(log10(n))
nines = tens * 9
print(nines + sumdigs(n - (10 ** tens - 1)))


n = int(input())
s = 0
while n > 0:
	if n < 10:
		s += n
		n = 0
	elif n % 10 == 9:
		s += 9
		n //= 10
	else:
		s += 10 + n % 10
		n = n // 10 - 1
print(str(s))


def sum_of_digits(x):
	sod = 0
	while x > 0:
		sod += x % 10
		x = int(x / 10)
	return sod

def count9(x):
	return list(str(x)).count('9')

def count_total_digit_number(x):
	x = int(x)
	return len(str(x))

def solution1():
	n = int(input())
	ctdn = count_total_digit_number(n)
	c9 = count9(n)
	if c9 < ctdn - 1 or (c9 == ctdn - 1 and str(n)[0] == '9'):
		number = n
		while count9(number) != ctdn - 1 or (c9 == ctdn - 1 and str(number)[0] == '9'):
			number -= 1
		print(sum_of_digits(number) + sum_of_digits(n - number))
	else:
		print(sum_of_digits(n))

def solution2():
	n = int(input())
	ctdn = count_total_digit_number(n)
	if ctdn == count9(n):
		print(sum_of_digits(n))
		exit()
	if ctdn == 1:
		print(n)
		exit()
	s = 0
	lst = list(str(n))
	for i in range(ctdn):
		if len(lst) == 1:
			if lst[0] == '9':
				break
			else:
				s += int(lst[0])
				break
		if len(lst) == lst.count('9'):
			s += 9
		else:
			s += 10 + int(lst[0]) - 1
		del lst[0]
	print(s)
solution2()


n = input()
m = int(n[0]) * pow(10, len(n) - 1) - 1
n = int(n) - m

def digtSum(x):
	res = 0
	while x > 0:
		res += x % 10
		x //= 10
	return res
print(digtSum(n) + digtSum(m))


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

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

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
n = input()
print(9 * (len(n) - 1) + sum(map(int, list('0' + str(int(n) - int('0' + '9' * (len(n) - 1)))))))


n = int(input())
ans = 0
while n % 10 == 9:
	ans += 9
	n //= 10
if n == 0:
	print(ans)
else:
	dig = 0
	while n:
		ans += n % 10
		dig += 1
		n //= 10
	print(ans + (dig - 1) * 9)


strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))

def sumOfDigit(num):
	s = 0
	while num > 0:
		s += num % 10
		num //= 10
	return s
i = input()
l = len(i)
n = int(i)
if n > 9:
	a = 9 * (l - 1)
	print(a + sumOfDigit(n - int('9' * (l - 1))))
else:
	print(n)


n = str(input())
ans = 0
a = ''
b = ''
t = str(int(n[0]) - 1)
if t == 0:
	a = '9' * (len(n) - 1)
	b = str(int(n) - int(a))
else:
	a = str(int(n[0]) - 1) + '9' * (len(n) - 1)
	b = str(int(n) - int(a))
for i in range(len(a)):
	ans += int(a[i])
for x in range(len(b)):
	ans += int(b[x])
print(ans)


u = input('')
n = int(u)
largest = None
w = len(u) - 1
if n < 10:
	sum = n
elif n >= 10:
	k = 10 ** w - 1
	m = n - k
	l = str(k)
	a = str(m)
	sum = 0
	for i in l:
		sum = sum + int(i)
	for b in a:
		sum = sum + int(b)
print(sum)


n = input()
s = list(n)
a = ''
if s.__len__() > 1:
	if s[0] == 1:
		for i in range(s.__len__() - 1):
			s[i] = 9
	else:
		s[0] = int(s[0]) - 1
		for i in range(s.__len__()):
			if i > 0:
				s[i] = 9
	for i in range(s.__len__()):
		if s[i] == 0:
			continue
		else:
			a += str(s[i])
	a = int(a)
	b = int(n) - a
	ans = int(0)
	while a > 0:
		ans += a % 10
		a //= 10
	while b > 0:
		ans += b % 10
		b //= 10
	print(ans)
else:
	print(s[0])


def sunOfDig(a):
	s = 0
	for i in str(a):
		s += int(i)
	return s
a = input()
maxS = sum([9] * (len(a) - 1))
if a[0] == '1':
	print(maxS + sunOfDig(int(a) - 10 ** (len(a) - 1) + 1))
else:
	print(maxS + int(a[0]) - 1 + sunOfDig(int(a) - int(a[0]) * 10 ** (len(a) - 1) + 1))


def f(a):
	a = sum(map(int, list(str(a))))
	return a
n = input()
l = len(n)
if l == 1:
	print(n)
	exit()
s = ''
for _ in range(l - 1):
	s += '9'
s = int(s)
rest = str(int(n) - s)
s = str(s)
ans = (l - 1) * 9
for i in rest:
	ans += int(i)
print(ans)


n = int(input())
a = 0
b = 0
s = 0
k = 1
while a + 9 * k < n:
	a += 9 * k
	k *= 10
	s += 9
b = n - a
while b > 0:
	s += b % 10
	b //= 10
print(s)


def calc(a, b):
	sum = 0
	while a > 0:
		ost = a % 10
		a = int(a / 10)
		sum += ost
	while b > 0:
		ost = b % 10
		b = int(b / 10)
		sum += ost
	return sum
n = int(input())
a = n
length = 1
while a > 10:
	a = int(a / 10)
	length = length * 10
a = length - 1
b = n - a
sum1 = calc(a, b)
sum2 = calc(a - 1, b + 1)
sum2 = calc(a + 1, b - 1)
print(max(sum1, sum2))


n = input()
ans = 9 * (len(n) - 1) + sum([int(i) for i in str(int(n) - int('0' + '9' * (len(n) - 1)))])
print(ans)


n = int(input())
s = str(n)
if n < 10:
	print(n)
else:
	a = '9' * (len(s) - 1)
	b = n - int(a)

	def sum(number):
		s = 0
		for digit in str(number):
			s += int(digit)
		return s
	ans = sum(a) + sum(b)
	print(ans)


n = int(input())
counter = 0
coef = 0
while n >= 9 * 10 ** coef:
	n -= 9 * pow(10, coef)
	counter += 9
	coef += 1
while n >= 10:
	counter += n % 10
	n //= 10
counter += n
print(counter)
exit(0)


n = int(input())
sa = '0'

def comp(k):
	a = int(k)
	b = n - a
	return b
while comp(sa) >= 0:
	if comp(sa + '9') >= 0:
		sa += '9'
	else:
		break
print(sum((int(h) for h in sa + str(comp(sa)))))


MX = 13
n = input()
while len(n) < MX:
	n = '0' + n
n = n[::-1]
best = 0
for mask in range(1 << MX):
	if 1 << 12 & mask:
		continue
	ans = 0
	bad = False
	for i in range(MX):
		has = int(1 << i & mask != 0)
		has_prev = 0 if i == 0 else 1 << i - 1 & mask != 0
		cur = int(n[i]) + has * 10 - has_prev
		bad |= cur < 0
		bad |= cur == 19
		ans += cur
	if not bad:
		best = max(ans, best)
print(best)


import math as mt

def done(n, m):
	ans1 = 0
	ans2 = 0
	while n:
		ans1 += n % 10
		n //= 10
	while m:
		ans2 += m % 10
		m //= 10
	return ans1 + ans2

def build(n):
	return int((n - 1) * '9')
n = int(input())
s = len(str(n))
if n <= 9:
	print(n)
	exit()
b = build(s)
print(done(n - b, b))


def s(x):
	return sum([int(i) for i in str(x)])
n = int(input())
a = 0
ans = 0
while a <= n:
	ans = max(ans, s(a) + s(n - a))
	a = 10 * a + 9
print(ans)


def suma(n):
	output = 0
	for i in str(n):
		output += int(i)
	return output
n = int(input())
if n <= 10:
	print(n)
else:
	first = int(str(int(str(n)[0]) - 1) + (len(str(n)) - 1) * '9')
	print(suma(first) + suma(n - first))


n = int(input())
a = 0
b = 0
sn = str(n)
while a <= n:
	a *= 10
	a += 9
a //= 10
b = n - a
print(sum([int(x) for x in str(a).strip()]) + sum([int(x) for x in str(b).strip()]))


from math import floor, log10
n = int(input())
res = 0
places = floor(log10(n)) + 1
for place in range(places):
	for i in range(1, 11):
		a = i * 10 ** place - 1
		if a > n:
			break
		b = n - a
		sum = 0
		while a:
			sum += a % 10
			a //= 10
		while b:
			sum += b % 10
			b //= 10
		res = max(res, sum)
print(res)


N = int(input())
mx = N // 2
for i in range(1, len(str(N)) + 1):
	m = int('9' * i)
	if m <= N:
		mx = m
S = lambda x: sum([int(i) for i in str(x)])
print(str(S(mx) + S(N - mx)))


import os
import sys
from io import BytesIO, IOBase
import math
from queue import Queue
import itertools
import bisect
import heapq

def main():
	pass
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')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	for i in range(2, n + 1):
		if primes[i]:
			for j in range(i + i, n + 1, i):
				primes[j] = False
	p = []
	for i in range(0, n + 1):
		if primes[i]:
			p.append(i)
	return p

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac

def sod(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s
n = int(input())
if n < 10:
	print(n)
else:
	t = int(math.log(n, 10))
	ans = t * 9
	val = 9
	for i in range(0, t - 1):
		val *= 10
		val += 9
	n -= val
	print(ans + sod(n))


t = int(input())
k = t // 2
l = len(str(k))
a = int(str(k)[0] + '9' * (l - 1))
b = t - a
s = 0
while a != 0:
	s += a % 10
	a = a // 10
while b != 0:
	s += b % 10
	b = b // 10
print(s)


def S(n):
	soma = 0
	while n >= 10:
		soma += n % 10
		n = int(n / 10)
	soma += n
	return soma
n = input()
tamanho = len(n)
n = int(n)
a = 0
for i in range(tamanho - 1):
	a += 9 * 10 ** i
b = n - a
print(S(a) + S(b))


n = int(input())
l = list(str(n))
s = sum([int(i) for i in l])
digits = len(l)
carry = 0
ans = 0
for i in range(digits - 1, -1, -1):
	e = l[i]
	if i == 0:
		if carry:
			ans += int(e) - 1
		else:
			ans += int(e)
	elif i == digits - 1:
		if e == '9':
			ans += 9
		else:
			ans += int(e) + 10
			carry = 1
	elif e == '9':
		if carry:
			ans += 18
		else:
			ans += 9
	else:
		if carry:
			ans += int(e) + 9
		else:
			ans += int(e) + 10
		carry = 1
print(ans)


a = input()
a = [int(x) for x in list(a)]
ans = 0
borrow = 0
while a:
	if len(a) == 1:
		ans += a[0]
		del a[0]
		break
	for el in a:
		if el == 0:
			del a[0]
		else:
			break
	if len(a) == 0:
		break
	if a[len(a) - 1] != 9:
		ans += a[len(a) - 1] + 10
		borrow = 1
	else:
		ans += 9
	del a[len(a) - 1]
	for x in range(len(a) - 1, -1, -1):
		if a[x] != 0:
			a[x] -= borrow
			borrow = 0
			break
		elif borrow:
			a[x] = 9
print(ans)


n = int(input())
a = n
c = 0
while a >= 10:
	a //= 10
	c += 1
b = a * 10 ** c - 1
a = n - b
c = 0
while a != 0:
	c += a % 10
	a //= 10
a = b
while a != 0:
	c += a % 10
	a //= 10
print(c)


n = int(input())
d = 9
while d * 10 + 9 <= n:
	d = d * 10 + 9
k = n - d
x = 0
y = 0
while d > 0:
	x += d % 10
	d = d // 10
while k > 0:
	y += k % 10
	k = k // 10
if n <= 9:
	print(n)
else:
	print(x + y)


def kek(x):
	d = 0
	while x > 0:
		d += x % 10
		x = x // 10
	return d
n = int(input())
a = 0
while a * 10 + 9 <= n:
	a = a * 10 + 9
print(kek(a) + kek(n - a))


def digSum(n):
	if n == 0:
		return n
	return n % 10 + digSum(n // 10)
n = input()
a = str(int(n[0]) - 1) + '9' * (len(n) - 1)
print(int(n[0]) - 1 + 9 * (len(n) - 1) + digSum(int(n) - int(a)))


n = input()
one = 0
s = 0
for i in range(len(n) - 1, -1, -1):
	cur = int(n[i]) - one
	if cur == -1:
		cur = 9
	if i != 0:
		if cur != 9:
			s += cur + 10
			one = 1
		else:
			s += cur
			if one != 1:
				one = 0
	else:
		s += cur
print(s)


class CodeforcesTask1060BSolution:

	def __init__(self):
		self.result = ''
		self.n = 0

	def read_input(self):
		self.n = int(input())

	def process_task(self):
		if self.n < 10:
			self.result = str(self.n)
		else:
			self.result = str(sum([9] * (len(str(self.n)) - 1) + [int(x) for x in str(self.n - int('9' * (len(str(self.n)) - 1)))]))

	def get_result(self):
		return self.result
Solution = CodeforcesTask1060BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


def su(a):
	s = 0
	while a != 0:
		s += a % 10
		a //= 10
	return s
n = int(input())
l = len(str(n))
p = n // 10 ** (l - 1) * 10 ** (l - 1) - 1
q = n % 10 ** (l - 1) + 1
print(su(p) + su(q))


n = int(input())
k = 0
kd = 0
while k * 10 + 9 < n:
	kd += 1
	k *= 10
	k += 9
ans = kd * 9
n1 = n - k
while n1:
	ans += n1 % 10
	n1 //= 10
print(ans)


n = input()
len_n = len(n)
a1 = int(n[0]) - 1
d = int(n) - a1 * 10 ** (len_n - 1)
for i in range(0, len_n - 1):
	d -= 9 * 10 ** i
d_str = str(d)
su = a1 + 9 * (len_n - 1)
for i in range(0, len(d_str)):
	su += int(d_str[i])
print(su)


import os
import sys
from io import BytesIO, IOBase
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')

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

def SieveOfEratosthenes(n):
	cnt = 0
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

def ssinp():
	return input()

def iinp():
	return int(input())

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

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

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
n = iinp()
if len(str(n)) == 1:
	p(n)
else:
	a = int('9' * (len(str(n)) - 1))
	b = n - a
	ans = 0
	for c in str(a):
		ans += int(c)
	for c in str(b):
		ans += int(c)
	p(ans)


def f():
	x = input()
	l = len(x)
	sum = 0
	if l == 1:
		print(int(x))
		return
	nine = ''
	for _ in range(l - 1):
		nine += '9'
	nine = int(nine)
	extra = int(x) - nine
	nine = str(nine)
	extra = str(extra)
	sum = len(nine) * 9
	for a in extra:
		sum += int(a)
	print(sum)
f()


import math as m
n = int(input())
a = 9
while n > a:
	a = 10 * a + 9
a //= 10
b = n - a
print(sum(map(int, str(a))) + sum(map(int, str(b))))


(n, a1) = (int(input()), 0)
if n < 18:
	print(n)
else:
	k = n - int('9' * (len(str(n)) - 1))
	for i in str(k):
		a1 += int(i)
	for i in str(n - k):
		a1 += int(i)
	print(a1)


n = input()
l = len(n)
s = 0
if int(n) > 10:
	temp = int(n[0]) - 1
	new_n = str(temp)
	chin = '9' * (int(l) - 1)
	new_n = new_n + chin
	for i in new_n:
		s = s + int(i)
	conlai = int(n) - int(new_n)
	for i in str(conlai):
		s = s + int(i)
	print(s)
else:
	print(int(n))


def mainA():
	n = int(input())
	s = input()
	cnt = 0
	for i in s:
		if i == '8':
			cnt += 1
	print(min(cnt, n // 11))

def mainB():

	def get(n):
		ret = 0
		while n > 0:
			ret += n % 10
			n //= 10
		return ret
	n = int(input())
	if n <= 9:
		print(n)
		return
	t = 9
	while n > t:
		t = t * 10 + 9
	t //= 10
	print(get(t) + get(n - t))
mainB()


n = int(input())

def sum_d(l):
	sums = 0
	while l > 0:
		sums += l % 10
		l = l // 10
	return sums
if n < 10:
	print(n)
else:
	nn = n
	lens = len(str(nn))
	ans = '9' * (lens - 1)
	ans = int(ans)
	f_ans = sum_d(ans) + sum_d(n - ans)
	print(f_ans)


def S(num):
	soma = 0
	while num != 0:
		soma += num % 10
		num = num // 10
	return soma
n = input()
a = []
for i in range(len(n) - 1):
	a.append(9)
aux = int(n[0]) - 1
a = [aux] + a
for i in range(len(a)):
	a[i] = str(a[i])
a = ''.join(a)
a = int(a)
n = int(n)
b = n - a
print(S(a) + S(b))


def sumDigit(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s
n = int(input())
m = 0
while n > m * 10 + 9:
	m = m * 10 + 9
print(sumDigit(m) + sumDigit(n - m))


from math import *
n = int(input())
base = int(log10(n))
val = int(pow(10, base)) - 1
other = n - val
ans = 9 * base
while other > 0:
	ans += other % 10
	other = other // 10
print(ans)


s = input()
l = []
a = ''
if len(s) == 1:
	print(s)
else:
	for i in range(0, len(s) - 1):
		a = a + str(9)
	b = int(s) - int(a)
	sum = 9 * len(a)
	for i in str(b):
		sum = sum + int(i)
	print(sum)


n = int(input())
q = len(str(n))

def sumd(n):
	sumf = 0
	p = len(str(n))
	for i in range(p):
		sumf += n // 10 ** (p - 1 - i)
		n = n % 10 ** (p - 1 - i)
	return sumf
x = 10 ** (q - 1) - 1
y = n - x
print(int(sumd(x) + sumd(y)))


n = input()
l = len(n)
s = '9' * (l - 1)
if n == s + '9':
	print(sum(list(map(int, str(s)))) + 9)
else:
	s = chr(ord(n[0]) - 1) + s
	x = list(map(int, s))
	a = int(s)
	b = int(n) - a
	y = list(map(int, str(b)))
	print(sum(x) + sum(y))


def suma(n):
	return sum(map(int, str(n)))
n = int(input())
if n <= 18:
	print(n)
else:
	first = int(str(int(str(n)[0]) - 1) + (len(str(n)) - 1) * '9')
	print(suma(first) + suma(n - first))


def getSum(n):
	sum = 0
	while n > 0:
		sum += int(n % 10)
		n = int(n / 10)
	return sum
n = int(input())
if n < 19:
	print(n)
elif n == 19:
	print(10)
else:
	x = y = 0
	if n % 2 != 0:
		x = n // 2
		y = x + 1
	else:
		x = y = n // 2
	sx = str(x)
	ln = len(sx)
	ln -= 1
	sx = sx[1:]
	sx = int(sx)
	tmp = str()
	for i in range(0, ln):
		tmp = tmp + str(9)
	tmp = int(tmp)
	sx = tmp - sx
	x = x + sx
	y = y - sx
	x = getSum(x)
	y = getSum(y)
	print(x + y)


def cou(n1, n2):
	ans = 0
	for i in range(0, len(n1)):
		ans += int(n1[i])
	for i in range(0, len(n2)):
		ans += int(n2[i])
	return ans

def magic(numList):
	s = map(str, numList)
	s = ''.join(s)
	s = int(s)
	return s
x = int(input())
digits = [int(n) for n in str(x)]
for i in range(0, len(digits)):
	if i != 0:
		digits[i] = 9
	else:
		digits[0] -= 1
num1 = magic(digits)
num2 = x - num1
print(cou(str(num1), str(num2)))


n = input()
if int(n) < 10:
	print(n)
else:
	sa = '9' * (len(n) - 1)
	b = int(n) - int(sa)
	sb = str(b)
	sum = 0
	for i in sa:
		sum += int(i)
	for i in sb:
		sum += int(i)
	print(sum)


n = int(input())
st = str(n)
if len(st) > 1:
	val = int((len(st) - 1) * '9')
	n2 = str(n - val)
	val = 0
	for i in n2:
		val += int(i)
	val += 9 * (len(st) - 1)
	print(val)
else:
	print(n)


n = int(input())
s = 0
m = 0
while m <= n:
	s = s + 9
	m = m * 10 + 9
y1 = n - m // 10
s = s - 9
y = str(y1)
for i in y:
	s = s + int(i)
print(s)


def s(x):
	sum = 0
	for i in str(x):
		sum += int(i)
	return sum
n = input()
if len(n) > 1:
	p = int('9' * (len(str(n)) - 1))
	print(s(p) + s(int(n) - p))
else:
	print(n)
	exit()


def s(x):
	res = 0
	while x > 0:
		res += x % 10
		x //= 10
	return res
n = input()
ans = 9 * (len(n) - 1)
n = int(n) - 10 ** (len(n) - 1) + 1
print(ans + s(n))


n = int(input())
k = len(str(n)) - 1
a = 10 ** k - 1
cnt = 0
n -= a
while n > 0:
	cnt += n % 10
	n //= 10
print(cnt + k * 9)


n = input()
carry = 0
output = 0
for d in map(int, n[:0:-1]):
	if d == 9 and carry == 0:
		output += 9
		carry = 0
	else:
		output += 9 + d + 1 - carry
		carry = 1
output += int(n[0]) - carry
print(output)


def read():
	return int(input())
N = read()
NUM = len(str(N))
a = 10 ** (NUM - 1) - 1
b = N - a

def sum_(n):
	arr = list((int(e) for e in str(n)))
	return sum(arr)
print(sum_(a) + sum_(b))