import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    auto S = sread();
    long ans = long.max;
    bool[char] d;
    foreach (c; S)
        d[c] = true;
    if (d.keys.length == 1)
    {
        writeln(0);
        return;
    }
    foreach (c; d.keys)
    {
        ans = ans.min(solve(S, c));
    }
    writeln(ans);
}

long solve(string S, char c)
{
    bool flag = true;
    string newS = "";
    foreach (i; 0 .. S.length - 1)
    {
        if (S[i] == c || S[i + 1] == c)
            newS ~= c;
        else
        {
            newS ~= S[i];
            flag = false;
        }
    }
    if (flag)
    {
        return 1;
    }
    else
    {
        return 1 + solve(newS, c);
    }
}
