Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim n As String = NextString()
        Dim flg As Integer

        For i As Integer = 0 To Len(n) - 1
            If i <> 0 And n(i) <> "9"c Then
                flg = 1
            End If
        Next

        WriteLine(Convert.ToInt32(n(0) & "") + 9 * (Len(n) - 1) - flg)
    End Sub

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function
End Module
