fun main(args: Array<String>) {
    val s = readLine()!!
    var ans = Int.MAX_VALUE
    for (last in 'a'..'z') {
        ans = Math.min(ans, solve(s, last))
    }
    println(ans)
}

fun solve(S: String, last: Char): Int {
    if (!S.contains(last)) {
        return Int.MAX_VALUE
    }
    var res = 0
    var s = S
    while (true) {
        if (s == last.toString().repeat(s.length)) {
            return res
        }
        s = (0 until s.length - 1).map {
            when (last) {
                s[it], s[it + 1] -> last
                else -> s[it]
            }
        }.joinToString("")
        res++
    }
}
