
object Main extends App {
    
    def is_ok(s: Array[Char]): Boolean = {
        if (s.isEmpty) {
            true
        } else {
            val c = s.head
            s.map(_ == c).reduceLeft(_ && _)
        }
    }
    
    def solve_impl(_s: Array[Char], c: Int): Int = {
        if (is_ok(_s)) {
            c
        } else {
            val s = _s.tail
            val m = s.groupBy(identity).map(g => g._2.length).reduceLeft(_ max _)
            val set = s.groupBy(identity).filter(g => g._2.length == m).map(g => g._1)
            
            for (ch <- set) {
                for (i <- 0 until s.length) {
                    if (_s(i) == ch || _s(i+1) == ch) {
                        s(i) = ch
                    }
                }
            }
            
            solve_impl(s, c + 1)
        }
    }
    
    def solve(s: Array[Char]): Int = {
        solve_impl(s, 0)
    }
    
    val sc = new java.util.Scanner(System.in)
    val str = sc.next
    
    val s = str.toArray
    
    println(solve(s))
}