import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val s = cin.next()
    val l = s.length
    
    var rec_all = -1

    for (i in 0..l-1) {
        val c = s[i]
        var count = 0
        var rec_max = 0

        for (j in 0..l-1) {
            val k = l - j - 1
            if (s[k] == c) {
                count = 0
            } else {
                count += 1
                if (count > rec_max) {
                    rec_max = count
                }
            }
        }

        if (0 > rec_all || rec_all > rec_max) {
            rec_all = rec_max
        }
    }

    println(rec_all)
}