import Foundation

extension String {
    func toIntList() -> [Int] {
        return self.split(separator: " ").map{Int($0)!}
    }
    
    func toList() -> [String] {
        return self.map{String($0)}
    }
    
    func count(c:Character) -> Int{
        var result = 0

        for e in self{
            if e == c{
                result += 1
            }
        }
        return result
    }

    func counter() -> Dictionary<Character, Int>{
        var result:[Character:Int] = [:]
        
        for c in self{
            guard let _ = result.index(forKey: c) else {
                result[c] = 1
                continue
            }
            result[c]! += 1
        }
        return result
    }
}

extension Int {
    func toBin() -> String {
        return String(self, radix: 2)
    }
    
    func toD() -> Double {
        return Double(self)
    }
}

extension Double {
    func toI() -> Int {
        return Int(self)
    }
}

extension Array where Element: Equatable{
    func count(n:Self.Element) -> Int{
        var result = 0
        for e in self{
            if e == n{
                result += 1
            }
        }
        return result
    }
}


func agc016a() -> Int{
    var S = readLine()!
    let N = S.count
    let counter = S.counter()
    var answer = 999
    for c in counter.keys{
        var t = S
        var a = 0
        while t.count(c: c) != t.count {
            var tmp = ""
            for i in 0..<t.count-1 {
                let index = t.index(t.startIndex, offsetBy: i)
                let indexPlus = t.index(t.startIndex, offsetBy: i+1)
                if t[index] == c || t[indexPlus] == c{
                    tmp.append(c)
                } else {
                    tmp.append(t[index])
                }
            }
            a += 1
            t = tmp
        }
        answer = min(a, answer)
    }
    return answer
}

print(agc016a())
