n = input()
if int(n) < 10:
    print(int(n))
    exit()
flag = n[1:] != '9' * (len(n) - 1)
print(int(n[0]) - flag + 9 * (len(n) - 1))

3c9e911fc5cbeab96a754a250da8fa814897c15a
<mask token>

<mask token>
if int(n) < 10:
    print(int(n))
    exit()
<mask token>
print(int(n[0]) - flag + 9 * (len(n) - 1))

n = input()
if int(n) < 10:
    print(int(n))
    exit()
flag = n[1:] != '9' * (len(n) - 1)
print(int(n[0]) - flag + 9 * (len(n) - 1))
