object Main extends App {
	val S = scala.io.StdIn.readLine

	var a = new Array[Int](26)

	def test1(x: List[Char]): Unit = {
		x match {
			case t::rest => {
				a(t.toInt - 97) = a(t.toInt - 97) + 1
				test1(rest)
			}
			case Nil => 
		}
	}

	def test2: Boolean = {
		var temp = 0
		for(i <- 0 to 25){
			if(a(i) != 0) temp = temp + 1
		}

		if(temp == 1){
			return true;
		}else{
			return false;
		}
	}

	def init() = for(i<-0 to 25) a(i) = 0



	var i = 0
	init()
	var read = S.toList
	test1(read)

	while(! test2){
		val size = read.size - 1
		var write: List[Char] = List()

		if(a.max == 1){
			for(j <- 0 until size){
				if(read(j).toInt < read(j+1).toInt){
					write = write :+ read(j+1)
				}else{
					write = write :+ read(j)
				}
			}

		}else{

		for(j <- 0 until size){
			if(a(read(j).toInt - 97) < a(read(j+1).toInt - 97)){
				write = write :+ read(j+1)
			}else{
				write = write :+ read(j)
			}
		}
		}

		read = write
		i = i + 1
		init()
		test1(read)
	}

	println(i)



}