N = eval(input())

ans = sum(int(c) for c in N)



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

    t = sum(int(c) for c in N[:i]) - 1 + 9 * (len(N) - i)

    ans = max(ans, t)

print(ans)
S = eval(input())

N = int(S)

ans = sum(map(int,S))



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

    n = str(int(S[:i]) - 1)

    t = sum(map(int,n)) + 9*(len(S)-i)

    ans = max(ans,t)

print(ans)
N = eval(input())
ans = sum(int(c) for c in N)
for i in range(1, len(N)):
    t = sum(int(c) for c in N[:i]) - 1 + 9 * (len(N) - i)
    ans = max(ans, t)
print(ans)

S = eval(input())
N = int(S)
ans = sum(map(int, S))
for i in range(1, len(S)):
    n = str(int(S[:i]) - 1)
    t = sum(map(int, n)) + 9 * (len(S) - i)
    ans = max(ans, t)
print(ans)

-N = eval(input()) -ans = sum(int(c) for c in N) -for i in range(1, len(N)): -    t = sum(int(c) for c in N[:i]) - 1 + 9 * (len(N) - i) +S = eval(input()) +N = int(S) +ans = sum(map(int, S)) +for i in range(1, len(S)): +    n = str(int(S[:i]) - 1) +    t = sum(map(int, n)) + 9 * (len(S) - i)