#include <bits/stdc++.h>
using namespace std;

int main(){
	string s;
	cin >> s;

	int ans = 1e9;
	for (int i = 0;i < 26;i++) {
		char c = 'a' + i;
		string tmp = s;
		int count = 0;
		while (string(tmp.size(), c) != tmp) {
			for (int j = 0;j < tmp.size() - 1;j++) {
				if (tmp[j + 1] == c) {
					tmp[j] = c;
				}
			}
			tmp.pop_back();
			count++;
		}
		ans = min(ans, count);
	}
	cout << ans << endl;

	return 0;
}