Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim s As String = NextString()
        Dim dic(s.Length - 1) As HashSet(Of Char)
        Dim flg As Boolean = False

        For i As Integer = 0 To s.Length - 1
            dic(i) = New HashSet(Of Char) From {s(i)}
        Next

        Do
            For c As Byte = Asc("a"c) To Asc("z"c)
                For i As Integer = 0 To dic.Length - 1
                    If Not dic(i).Contains(Chr(c)) Then
                        GoTo exitLoop
                    End If
                Next
                flg = True
exitLoop:
            Next

            For i As Integer = 0 To dic.Length - 2
                For Each v As Char In dic(i + 1)
                    dic(i).Add(v)
                Next
            Next

            If flg Then Exit Do
            ReDim Preserve dic(dic.Length - 2)
        Loop

        WriteLine(s.Length - dic.Length)
    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
