#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000007;
vector<long long> blk;
vector<char> color;
long long c = 0;
string s;
long long deleteBlock() {
  long long smallest = *min_element(blk.begin() + 1, blk.end() - 1);
  if (blk[0] * 2 < smallest) smallest = blk[0] * 2;
  if (blk[blk.size() - 1] * 2 < smallest) smallest = blk[blk.size() - 1] * 2;
  if (smallest % 2 == 1) smallest++;
  smallest /= 2;
  if (blk[0] <= smallest) {
    blk.erase(blk.begin());
    color.erase(color.begin());
  } else
    blk[0] -= smallest;
  for (int i = 1; i < blk.size() - 1; i++) {
    if (blk[i] <= smallest * 2) {
      blk.erase(blk.begin() + i);
      color.erase(color.begin() + i);
      i--;
    } else
      blk[i] -= smallest * 2;
  }
  if (blk[blk.size() - 1] <= smallest) {
    blk.erase(blk.begin() + blk.size() - 1);
    color.erase(color.begin() + color.size() - 1);
  } else
    blk[blk.size() - 1] -= smallest;
  for (int i = 1; i < blk.size(); i++) {
    if (color[i] == color[i - 1]) {
      blk[i - 1] += blk[i];
      blk.erase(blk.begin() + i);
      color.erase(color.begin() + i);
      i--;
    }
  }
  return smallest;
}
int main() {
  getline(cin, s);
  color.push_back(s[0]);
  long long tp = 1;
  for (int i = 1; i < s.length(); i++) {
    if (s[i] == s[i - 1]) {
      tp++;
      if (i == s.length() - 1) {
        blk.push_back(tp);
        tp = 1;
        color.push_back(s[i]);
      }
    } else {
      blk.push_back(tp);
      tp = 1;
      color.push_back(s[i]);
    }
  }
  while (blk.size() > 1) {
    c += deleteBlock();
  }
  cout << c;
}
