#include <bits/stdc++.h>
constexpr int MAX_N = 1001000;
using namespace std;
int n;
char s[MAX_N];
vector<pair<char, int>> exec(vector<pair<char, int>> v, int &ans) {
  int steps = v[0].second;
  for (int i = 0; i < v.size(); ++i) {
    if (i == 0 || i == v.size() - 1) {
      steps = min(steps, v[i].second);
    } else {
      steps = min(steps, (v[i].second + 1) / 2);
    }
  }
  vector<pair<char, int>> ans1;
  for (int i = 0; i < v.size(); ++i) {
    if (i == 0 || i == v.size() - 1) {
      v[i].second -= steps;
    } else {
      v[i].second -= 2 * steps;
    }
    if (v[i].second > 0) ans1.push_back(v[i]);
  }
  ans += steps;
  if (ans1.empty()) return ans1;
  vector<pair<char, int>> ans2;
  char c = ans1[0].first;
  int cnt = ans1[0].second;
  for (int i = 1; i < ans1.size(); ++i) {
    if (ans1[i].first == c)
      cnt += ans1[i].second;
    else {
      ans2.push_back({c, cnt});
      c = ans1[i].first;
      cnt = ans1[i].second;
    }
  }
  ans2.push_back({c, cnt});
  return ans2;
}
void print_v(vector<pair<char, int>> v) {
  for (auto p : v) {
    printf("<%c, %d> ", p.first, p.second);
  }
  printf("\n");
}
int main() {
  scanf(" %s", s);
  n = strlen(s);
  char c = s[0];
  int cnt = 1;
  vector<pair<char, int>> v;
  for (int i = 1; i < n; ++i) {
    if (s[i] == c)
      ++cnt;
    else {
      v.push_back({c, cnt});
      c = s[i];
      cnt = 1;
    }
  }
  v.push_back({c, cnt});
  int ans = 0;
  while (v.size() > 1) {
    v = exec(v, ans);
  }
  printf("%d\n", ans);
  return 0;
}
