#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int cvrst(string s, char c){
    int suma = 0;
    int x = 0;
    for(int i = 0; i < s.length(); i++){
        if(c == s[i])
            x = i;
            break;
    }
    for(int i = x; i < s.length(); i++){
    int k = i;
    int j = i;
    while(k < s.length()){
        if(s[k] == s[i])
            j = k;
        k++;
    }
        if (j > i){
            for(int k = i + 1; k < j; k++){
                if(s[k] != s[i]){
                    s[k] = s[i];
                    suma++;
                }
            }
    }
    }
    return suma;
}

int main()
{
    string s;
    cin >> s;
    int ans = cvrst(s, s[0]);
    string sx = s;
    string sy = s;
    sx[0] = sx[1];
    sy[s.length() - 1] = sy[s.length() - 2];
    for(int i = 1; i < s.length(); i++)
        if(cvrst(s, s[i]) < ans)
            ans = cvrst(s, s[i]);
    cout << min(ans, cvrst(sx, sx[0]) + 1);
    return 0;
}