#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
char a[N];
int n, pnext[N], pprev[N];
queue<int> examine, del;
bool examining[N], deleting[N];
bool deleted[N];
void del_Element(int x) {
  if (deleted[x]) return;
  deleted[x] = 1;
  deleting[x] = 0;
  if (pprev[x] != -1) pnext[pprev[x]] = pnext[x];
  if (pnext[x] != n) pprev[pnext[x]] = pprev[x];
}
int main() {
  scanf("%s%n\n", a, &n);
  for (int i = (0); i <= (n - 1); i++) {
    pprev[i] = i - 1;
    pnext[i] = i + 1;
  }
  for (int i = (0); i <= (n - 1); i++)
    if ((i - 1 >= 0 && a[i] != a[i - 1]) || (i + 1 < n && a[i] != a[i + 1]))
      deleting[i] = 1, del.push(i);
  int phrase = 0;
  while (!(examine.empty() && del.empty())) {
    phrase++;
    while (!del.empty()) {
      int u = del.front();
      del.pop();
      if (pprev[u] != -1 && !deleting[pprev[u]] && !deleted[pprev[u]] &&
          !examining[pprev[u]]) {
        examining[pprev[u]] = 1;
        examine.push(pprev[u]);
      }
      if (pnext[u] != n && !deleting[pnext[u]] && !deleted[pnext[u]] &&
          !examining[pnext[u]]) {
        examining[pnext[u]] = 1;
        examine.push(pnext[u]);
      }
      del_Element(u);
    }
    while (!examine.empty()) {
      int u = examine.front();
      examine.pop();
      examining[u] = 0;
      if ((pprev[u] != -1 && a[u] != a[pprev[u]]) ||
          (pnext[u] != n && a[u] != a[pnext[u]])) {
        deleting[u] = 1;
        del.push(u);
      }
    }
  }
  printf("%d\n", phrase);
  return 0;
}
