
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: Char, i: Int): Int = {
        if (is_ok(s)) {
            i
        } else {
            var _s = s.tail
            for (i <- 0 until _s.length) {
                if (s(i) == c || s(i + 1) == c) {
                    _s(i) = c
                }
            }
            solve_impl(_s, c, i + 1)
        }
    }
    
    def solve(s: Array[Char]): Int = {
        val sgb = s.groupBy(identity)
        //val m = sgb.map(_._2.length).reduceLeft(_ max _)
        //val set = sgb.filter(_._2.length == m).map(_._1)
        val set = sgb.map(_._1)  
        
        var l = List(1000)
        for (ch <- set) {
            l = solve_impl(s, ch, 0) :: l
        }
        l.reduceLeft(_ min _)
    }
    
    val sc = new java.util.Scanner(System.in)
    val str = sc.next
    
    val s = str.toArray
    
    println(solve(s))
}