#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
int l[1000001], r[1000001], f[26];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int i, n;
  string s;
  cin >> s;
  n = s.length();
  l[0] = 10000000;
  for (i = 1; i < n; i++) {
    if (s[i] == s[i - 1])
      l[i] = l[i - 1] + 1;
    else
      l[i] = 1;
  }
  r[n - 1] = 10000000;
  for (i = n - 2; i >= 0; i--) {
    if (s[i] == s[i + 1])
      r[i] = r[i + 1] + 1;
    else
      r[i] = 1;
  }
  for (i = 0; i < n; i++) {
    f[s[i] - 'a'] = max(f[s[i] - 'a'], min(l[i], r[i]));
  }
  for (i = 0; i < 26; i++) v.push_back(f[i]);
  sort(v.begin(), v.end());
  cout << v[v.size() - 2] << "\n";
  return 0;
}
