

def myAnswer(N:int)->int:

   K = len(str(N)) #桁数

   if(K == 1):return N

   c = N // 10**(K-1) #最上位の桁の数

   if((c*10**(K-1) + int("9"*(K-1)))<= N):

      return c + 9 *(K - 1)

   else:

      return c + 9 *(K - 1) -1 





def modelAnswer():

   tmp=1

def main():

   N = int(eval(input()))

   print((myAnswer(N)))



if __name__ == '__main__':

   main()
def myAnswer(N:int)->int:

   length = len(str(N))

   if(length == 1): return N

   l = list(str(N))

   tmp = 0

   for n in l[1:]:

      tmp += int(n)

   total = length * 9

   if(tmp == total - 9):

      return tmp + int(l[0])

   else:

      total += -9 + int(l[0]) - 1

      return total

def modelAnswer():

   tmp=1

def main():

   N = int(eval(input()))

   print((myAnswer(N)))



if __name__ == '__main__':

   main()
def myAnswer(N: int) -> int:
    K = len(str(N))  # 桁数
    if K == 1:
        return N
    c = N // 10 ** (K - 1)  # 最上位の桁の数
    if (c * 10 ** (K - 1) + int("9" * (K - 1))) <= N:
        return c + 9 * (K - 1)
    else:
        return c + 9 * (K - 1) - 1


def modelAnswer():
    tmp = 1


def main():
    N = int(eval(input()))
    print((myAnswer(N)))


if __name__ == "__main__":
    main()

def myAnswer(N: int) -> int:
    length = len(str(N))
    if length == 1:
        return N
    l = list(str(N))
    tmp = 0
    for n in l[1:]:
        tmp += int(n)
    total = length * 9
    if tmp == total - 9:
        return tmp + int(l[0])
    else:
        total += -9 + int(l[0]) - 1
        return total


def modelAnswer():
    tmp = 1


def main():
    N = int(eval(input()))
    print((myAnswer(N)))


if __name__ == "__main__":
    main()

-    K = len(str(N))  # 桁数 -    if K == 1: +    length = len(str(N)) +    if length == 1: -    c = N // 10 ** (K - 1)  # 最上位の桁の数 -    if (c * 10 ** (K - 1) + int("9" * (K - 1))) <= N: -        return c + 9 * (K - 1) +    l = list(str(N)) +    tmp = 0 +    for n in l[1:]: +        tmp += int(n) +    total = length * 9 +    if tmp == total - 9: +        return tmp + int(l[0]) -        return c + 9 * (K - 1) - 1 +        total += -9 + int(l[0]) - 1 +        return total