#!/usr/bin/env python3

s = eval(input())

digit = len(s)

if s[1:] == "9"*(digit-1):

    print((int(s[0])+9*(digit-1)))

else:

    print((int(s[0])+9*(digit-1)-1))
s = eval(input())

if len(s) == 1: print((int(s[0])))

elif s[1:] == "9"*(len(s)-1):

  print((int(s[0])+9*len(s)-9))

else: 

  print((int(s[0])+9*len(s)-10))                                    

#!/usr/bin/env python3
s = eval(input())
digit = len(s)
if s[1:] == "9" * (digit - 1):
    print((int(s[0]) + 9 * (digit - 1)))
else:
    print((int(s[0]) + 9 * (digit - 1) - 1))

s = eval(input())
if len(s) == 1:
    print((int(s[0])))
elif s[1:] == "9" * (len(s) - 1):
    print((int(s[0]) + 9 * len(s) - 9))
else:
    print((int(s[0]) + 9 * len(s) - 10))

-#!/usr/bin/env python3 -digit = len(s) -if s[1:] == "9" * (digit - 1): -    print((int(s[0]) + 9 * (digit - 1))) +if len(s) == 1: +    print((int(s[0]))) +elif s[1:] == "9" * (len(s) - 1): +    print((int(s[0]) + 9 * len(s) - 9)) -    print((int(s[0]) + 9 * (digit - 1) - 1)) +    print((int(s[0]) + 9 * len(s) - 10))