"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0].split("");
    
    let list = {};
    let stringCnt = [...new Set(S)].length;
    let cnt = 0;
    
    if(stringCnt === 1) {
        console.log(0);
        return;
    }
    
    for(let i in S) {
        if(list[S[i]]) {
            list[S[i]]++;
        } else {
            list[S[i]] = 1;
        }
    }
    
    for(let key of Object.keys(list)) {
        let previous = S;
        
        while(stringCnt !== 1) {
            let next = [];
            
            for(let i=0; i<previous.length-1; i++) {
                if(previous[i] === key || previous[~~i+1] === key) {
                    next.push(key);
                } else {
                    next.push(S[i]);
                }
            }
            
            previous  = next.join("");
            stringCnt = [...new Set(previous)].length;
        }
        
        cnt = Math.max(previous.length, cnt);
        
        stringCnt = [...new Set(S)].length;
    }
    
    console.log(S.length - cnt)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));