def ketawa(x):

    l = list(str(x))

    wa = 0

    for a in l:

        wa += int(a)

    return wa



n = int(eval(input()))

lst = list(str(n))

keta = len(str(n))









nine = int("".join([lst[0]] + ["9"]*(keta-1)))



if nine <= n:

    print((ketawa(nine)))

else:

    lst_head = str(int(lst[0]) - 1)

    nine = int("".join([lst_head] + ["9"]*(keta-1)))

    print((ketawa(nine)))
n = int(eval(input()))



lst = list(map(int,str(n)))

if len(lst) == 1:

    print(n)

elif set(lst[1:]) == {9}:

    print((lst[0] + 9*(len(lst)-1)))

else:

    print(((lst[0]-1) + 9*(len(lst)-1)))
def ketawa(x):
    l = list(str(x))
    wa = 0
    for a in l:
        wa += int(a)
    return wa


n = int(eval(input()))
lst = list(str(n))
keta = len(str(n))
nine = int("".join([lst[0]] + ["9"] * (keta - 1)))
if nine <= n:
    print((ketawa(nine)))
else:
    lst_head = str(int(lst[0]) - 1)
    nine = int("".join([lst_head] + ["9"] * (keta - 1)))
    print((ketawa(nine)))

n = int(eval(input()))
lst = list(map(int, str(n)))
if len(lst) == 1:
    print(n)
elif set(lst[1:]) == {9}:
    print((lst[0] + 9 * (len(lst) - 1)))
else:
    print(((lst[0] - 1) + 9 * (len(lst) - 1)))

-def ketawa(x): -    l = list(str(x)) -    wa = 0 -    for a in l: -        wa += int(a) -    return wa - - -lst = list(str(n)) -keta = len(str(n)) -nine = int("".join([lst[0]] + ["9"] * (keta - 1))) -if nine <= n: -    print((ketawa(nine))) +lst = list(map(int, str(n))) +if len(lst) == 1: +    print(n) +elif set(lst[1:]) == {9}: +    print((lst[0] + 9 * (len(lst) - 1))) -    lst_head = str(int(lst[0]) - 1) -    nine = int("".join([lst_head] + ["9"] * (keta - 1))) -    print((ketawa(nine))) +    print(((lst[0] - 1) + 9 * (len(lst) - 1)))