fun main(args : Array<String>) {
    val s = readLine()!!
    val sList = s.groupBy { it }

    var minCnt = Int.MAX_VALUE

    sList.forEach {
        val target = it.key
        val ts = target.toString().repeat(s.length)
        var ss = s
        var cnt = 0

        while (ss != ts.drop(cnt)) {
            var tmp = ""
            for (i in 0 until ss.length-1) {
                if (ss[i+1] == target) {
                    tmp += ss[i+1]
                } else {
                    tmp += ss[i]
                }
            }
            ss = tmp
            cnt++
        }

        minCnt = Math.min(minCnt, cnt)
    }

    println(minCnt)
}

