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, dchar[] s) {
        if (s.length == 1) return 0;

        auto cs = new dchar[s.length - 1];
        for (int i = 0; i < cs.length; i++) {
            if (s[i] == c || s[i+1] == c) cs[i] = c;
            else cs[i] = s[i];
        }

        if (cs.all!(e => e == c)) return 1;
        return f(c, cs.array) + 1;
    }

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

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