import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, core.bitop;

int r, c;
int[] sb;

void main() {
    string s = readln.chomp;
    int n = s.length.to!int;

    bool[] e = new bool[](26);

    foreach (ch ; s) {
        e[ch - 'a'] = 1;
    }

    if (e.count(1) == 1) {
        writeln(0);
        return;
    }

    int ans = 1000;

    foreach (char ch; 'a' .. 'z' + 1) {
        if (!e[ch - 'a']) continue;

        auto t = s.dup;
        int cnt;

        foreach (i ; 0 .. n - 1) {
            cnt++;

            foreach (j ; 0 .. n - 1 - i) {
                if (t[j + 1] == ch) {
                    t[j] = ch;
                }
            }

            bool flag = true;

            foreach (j ; 0 .. n - 1 - i) {
                if (t[j] != ch) {
                    flag = false;
                    break;
                }
            }

            debug {
                stderr.writeln(t[0 .. n - 1 - i]);
            }

            if (flag) break;
        }

        ans = min(ans, cnt);
    }

    writeln(ans);
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}