#include <bits/stdc++.h>
const int N = 1000000;
int maxans = 0, a[N], d[N], last;
char s[N];
void max(int x) { return (void)(maxans < x ? maxans = x : 0); }
void max(int &x, int y) { return (void)(x < y ? x = y : 0); }
int main() {
  scanf("%s", s);
  int n = strlen(s);
  s[n] = s[n - 1];
  for (int i = 0; i < n; i++) {
    if (s[i] != s[i + 1]) {
      if (last) max(d[a[last - 1]], 1);
      max(1);
      i++;
      continue;
    }
    if (last && s[i] != s[a[last - 1]]) {
      int x = d[a[last - 1]] + 1;
      max(x);
      if (last - 1) max(d[a[last - 2]], x);
      last--;
    } else {
      a[last++] = i;
    }
  }
  printf("%d\n", maxans);
  return 0;
}
