fun main(args: Array<String>) {
    val s = readLine() ?: return
    val count = s.groupBy { it }
        .map { entry ->
            val c = entry.key
            var count = 0
            var t = s.toCharArray().toMutableList()
            while (!t.all { a -> a == c }) {
                0.until(t.size - 1).forEach { i ->
                    if (t[i] == c || t[i + 1] == c) {
                        t[i] = c
                    }
                }
                count++
                t = t.dropLast(1).toMutableList()
            }
            count
        }.min()
    println(count.toString())
}