n = eval(input())

if len(n) == 1:

  print((int(n)))

else:

  all9flg = True

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

    if n[i] != "9":

      all9flg = False

  if all9flg:

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

  else:

    print((9 * (len(n) - 1) + int(n[0]) - 1))
n = eval(input())

k = len(n)

if all([i == "9" for i in n[1:]]):

  print((int(n[0]) + (k - 1) * 9))

else:

  print((int(n[0]) - 1 + (k - 1) * 9))

n = eval(input())
if len(n) == 1:
    print((int(n)))
else:
    all9flg = True
    for i in range(1, len(n)):
        if n[i] != "9":
            all9flg = False
    if all9flg:
        print((9 * (len(n) - 1) + int(n[0])))
    else:
        print((9 * (len(n) - 1) + int(n[0]) - 1))

n = eval(input())
k = len(n)
if all([i == "9" for i in n[1:]]):
    print((int(n[0]) + (k - 1) * 9))
else:
    print((int(n[0]) - 1 + (k - 1) * 9))

-if len(n) == 1: -    print((int(n))) +k = len(n) +if all([i == "9" for i in n[1:]]): +    print((int(n[0]) + (k - 1) * 9)) -    all9flg = True -    for i in range(1, len(n)): -        if n[i] != "9": -            all9flg = False -    if all9flg: -        print((9 * (len(n) - 1) + int(n[0]))) -    else: -        print((9 * (len(n) - 1) + int(n[0]) - 1)) +    print((int(n[0]) - 1 + (k - 1) * 9))