N = input().strip()

n = len(N)

cntmax = 0

for i in range(n):

    cntmax += int(N[i])

for j in range(n-1):

    x=N[:j]

    if N[j]!="0":

        x += str(int(N[j])-1)+"9"*(n-1-j)

        cnt = 0

        for i in range(n):

            cnt += int(x[i])

        cntmax = max(cntmax,cnt)

print(cntmax)       
N = input().strip()

k = len(N)

a = int(N[0])

if k==1:

    cmax = a

else:

    cnt = 0

    for i in range(k):

        cnt += int(N[i])

    cmax = max((a-1)+9*(k-1),cnt)

print(cmax)
N = input().strip()
n = len(N)
cntmax = 0
for i in range(n):
    cntmax += int(N[i])
for j in range(n - 1):
    x = N[:j]
    if N[j] != "0":
        x += str(int(N[j]) - 1) + "9" * (n - 1 - j)
        cnt = 0
        for i in range(n):
            cnt += int(x[i])
        cntmax = max(cntmax, cnt)
print(cntmax)

N = input().strip()
k = len(N)
a = int(N[0])
if k == 1:
    cmax = a
else:
    cnt = 0
    for i in range(k):
        cnt += int(N[i])
    cmax = max((a - 1) + 9 * (k - 1), cnt)
print(cmax)

-n = len(N) -cntmax = 0 -for i in range(n): -    cntmax += int(N[i]) -for j in range(n - 1): -    x = N[:j] -    if N[j] != "0": -        x += str(int(N[j]) - 1) + "9" * (n - 1 - j) -        cnt = 0 -        for i in range(n): -            cnt += int(x[i]) -        cntmax = max(cntmax, cnt) -print(cntmax) +k = len(N) +a = int(N[0]) +if k == 1: +    cmax = a +else: +    cnt = 0 +    for i in range(k): +        cnt += int(N[i]) +    cmax = max((a - 1) + 9 * (k - 1), cnt) +print(cmax)