#include <bits/stdc++.h>
using namespace std;
string s;
long long cnt[27];
long long count_(long long x) {
  if (x == 0) {
    if (s[x + 1] != s[x])
      return 1;
    else
      return 0;
  }
  if (x == s.size() - 1) {
    if (s[x - 1] != s[x])
      return 1;
    else
      return 0;
  }
  if (s[x + 1] != s[x] || s[x - 1] != s[x])
    return 1;
  else
    return 0;
}
void work() {
  cin >> s;
  long long count = 0, res = 0;
  for (long long i = 0; i < s.size(); i++) {
    if (!cnt[s[i] - 'a' + 1]) count++;
    cnt[s[i] - 'a' + 1]++;
  }
  while (1) {
    string tmp;
    for (long long i = 0; i < s.size(); i++) {
      bool f = count_(i);
      if (f) {
        cnt[s[i] - 'a' + 1]--;
        if (cnt[s[i] - 'a' + 1] == 0) count--;
        continue;
      } else
        tmp += s[i];
    }
    res++;
    s = tmp;
    if (count == 1 || count == 0) break;
  }
  cout << res << endl;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long cas;
  cas = 1;
  while (cas--) work();
}
