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

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto s = sread();
    long cnt = INF;
    if (s.allEqual())
    {
        writeln(0);
        return;
    }

    foreach (c; "abcdefghijklmnopqrstuvwxyz")
    {
        cnt = min(s.needchange(c), cnt);
    }
    cnt.writeln();
}

long needchange(string str, char c)
{
    if (str.length == 1)
        return 1;

    auto newstr = new char[](str.length - 1);
    foreach (i; iota(str.length - 1))
    {
        newstr[i] = (str[i] == c || str[i + 1] == c) ? c : str[i];
    }
    if (newstr.allEqual())
        return 1;
    else
        return 1 + needchange(newstr.to!string, c);
}

bool allEqual(T)(T s)
{
    bool ret = true;
    foreach (i; iota(s.length - 1))
        ret &= s[i] == s[i + 1];
    return ret;
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}
