import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
import std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	char[] s = readln.chomp.to!(char[]);
	
	int ans = 10000;
	foreach(c; s){
		int x = solve(s, c);
		if(x < ans) ans = x;
		}
	
	bool flag = 1;
	foreach(c; s) if(c != s[0]) flag = 0;
	if(flag) ans = 0;
	
	ans.writeln;
	
	}

int solve(char[] s, char c){
	char[] s1 = s;
	int count;
	while(1){
		bool flag = 1;
		char[] s2;
		for(int i = 0; i < s1.length - 1; i ++){
			if(s1[i] == c || s1[i + 1] == c) s2 ~= c;
			else{
				flag = 0;
				s2 ~= ' ';
				}
			}
		s1 = s2;
		count += 1;
		if(flag) break;
		}
	return count;
	}
