
object Main extends App {

  def isOk(cx: Seq[Char]): Boolean = {
    if (cx.length == 0) true
    else cx.map(_ == cx.head).reduce(_ && _)
  }

  def count(cx: Seq[Char], c: Char): Int = {
    @annotation.tailrec
    def loop(n: Int, _cx: Seq[Char]): Int = {
      if (isOk(_cx)) n
      else {
        val __cx = (0 until _cx.length - 1).map(i =>
          if (_cx(i) == c || _cx(i+1) == c) c
          else _cx(i)
        ).toSeq
            
        loop(n + 1, __cx)
      }
    }
    loop(0, cx)
  }

  def solve(cx: Seq[Char]): Int = 
    ('a' to 'z').map(c => count(cx, c)).reduce(_ min _)

  val sc = new java.util.Scanner(System.in)
  val str = sc.next
    
  System.out println solve(str.toList)
}