fun main(args: Array<String>) {
    val s = readLine()!!
    var dic = Array(s.length) { mutableSetOf<Char>() }
    var flg = false

    for (i in 0 until s.length) {
        dic[i] = mutableSetOf(s[i])
    }

    while (true) {
        for (c in 'a'..'z') {
            var i = 0
            while (i < dic.size) {
                if (!dic[i].contains(c)) {
                    break
                }
                i++
            }
            if (i == dic.size) {
                flg = true
            }
        }
        for (i in 0 until dic.size - 1) {
            for (v in dic[i + 1]) {
                dic[i].add(v)
            }
        }
        if (flg) {
            break
        }
        dic = dic.slice(0 until dic.size - 1).toTypedArray()
    }
    println(s.length - dic.size)
}
