import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(string s) {
    // 全ての文字を c にする
    int f(dchar c, string s) {
        auto cs = s.dup.array;
        int n = cast(int)s.length - 1; // 次の文字列の長さ
        foreach (i; 0..n) {
            bool ok = true;
            foreach (j; 0..n) {
                cs[j] = cs[j] == c ? cs[j] : cs[j+1];
                if (cs[j] != c) ok = false;
            }
            if (ok) return i + 1;
            n--;
        }
        return 0;
    }

    if (s.all!(c => c== s[0])) return 0;
    return s.map!(c => f(c, s)).reduce!min;
}

void main() {
    string s = read!string;
    writeln(calc(s));
}
