n = list(map(int, list(input()[::-1])))

l = len(n)



ans = dec = 0

for i in range(1<<l):

        cnt = 0

        for j in range(l):

                if j==l-1:

                        cnt += n[j] - dec

                        break

                if((i>>j)&1):

                        cnt += 9

                        dec = True

                else:

                        cnt += n[j] - dec

                        dec = False

        ans = max(ans, cnt)

print(ans)
n = eval(input())

l = len(n)



dp = [[0]*2 for i in range(l+1)]

dp[l] = [0,0]

for i in range(l):

    dp[l-i-1][0] = max(dp[l-i][0]+int(n[l-i-1]), dp[l-i][1]+int(n[l-i-1])-1)

    dp[l-i-1][1] = max(dp[l-i][0]+9, dp[l-i][1]+9)

dp[0][1] = max(dp[1][0]+int(n[0]), dp[1][1]+int(n[0])-1)

print((max(dp[0])))
n = list(map(int, list(input()[::-1])))
l = len(n)
ans = dec = 0
for i in range(1 << l):
    cnt = 0
    for j in range(l):
        if j == l - 1:
            cnt += n[j] - dec
            break
        if (i >> j) & 1:
            cnt += 9
            dec = True
        else:
            cnt += n[j] - dec
            dec = False
    ans = max(ans, cnt)
print(ans)

n = eval(input())
l = len(n)
dp = [[0] * 2 for i in range(l + 1)]
dp[l] = [0, 0]
for i in range(l):
    dp[l - i - 1][0] = max(
        dp[l - i][0] + int(n[l - i - 1]), dp[l - i][1] + int(n[l - i - 1]) - 1
    )
    dp[l - i - 1][1] = max(dp[l - i][0] + 9, dp[l - i][1] + 9)
dp[0][1] = max(dp[1][0] + int(n[0]), dp[1][1] + int(n[0]) - 1)
print((max(dp[0])))

-n = list(map(int, list(input()[::-1]))) +n = eval(input()) -ans = dec = 0 -for i in range(1 << l): -    cnt = 0 -    for j in range(l): -        if j == l - 1: -            cnt += n[j] - dec -            break -        if (i >> j) & 1: -            cnt += 9 -            dec = True -        else: -            cnt += n[j] - dec -            dec = False -    ans = max(ans, cnt) -print(ans) +dp = [[0] * 2 for i in range(l + 1)] +dp[l] = [0, 0] +for i in range(l): +    dp[l - i - 1][0] = max( +        dp[l - i][0] + int(n[l - i - 1]), dp[l - i][1] + int(n[l - i - 1]) - 1 +    ) +    dp[l - i - 1][1] = max(dp[l - i][0] + 9, dp[l - i][1] + 9) +dp[0][1] = max(dp[1][0] + int(n[0]), dp[1][1] + int(n[0]) - 1) +print((max(dp[0])))