import math

n=int(eval(input()))

s = str(n)

array = list(map(int, list(s)))

a1=sum(array)

size = int (math.log10(n))

a2=int(n/(10**size))-1+size*9

print((max(a1,a2)))

n = int(eval(input()))

c = None

res = 0

for i in range(1, len(str(n))+1):

    c = '9' * i

    if int(c) <= n:

        continue

    else:

        for j in range(9, -1, -1):

            if int(str(j) + str(c)[1:]) <= n:

                c = str(j) + str(c)[1:]

                break

        break

for i in range(len(c)):

    res += int(c[i])

print(res)
import math

n = int(eval(input()))
s = str(n)
array = list(map(int, list(s)))
a1 = sum(array)
size = int(math.log10(n))
a2 = int(n / (10**size)) - 1 + size * 9
print((max(a1, a2)))

n = int(eval(input()))
c = None
res = 0
for i in range(1, len(str(n)) + 1):
    c = "9" * i
    if int(c) <= n:
        continue
    else:
        for j in range(9, -1, -1):
            if int(str(j) + str(c)[1:]) <= n:
                c = str(j) + str(c)[1:]
                break
        break
for i in range(len(c)):
    res += int(c[i])
print(res)

-import math - -s = str(n) -array = list(map(int, list(s))) -a1 = sum(array) -size = int(math.log10(n)) -a2 = int(n / (10**size)) - 1 + size * 9 -print((max(a1, a2))) +c = None +res = 0 +for i in range(1, len(str(n)) + 1): +    c = "9" * i +    if int(c) <= n: +        continue +    else: +        for j in range(9, -1, -1): +            if int(str(j) + str(c)[1:]) <= n: +                c = str(j) + str(c)[1:] +                break +        break +for i in range(len(c)): +    res += int(c[i]) +print(res)