#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;
long long readInt() {
  bool minus1 = false;
  long long result = 0;
  char ch;
  ch = getchar();
  while (true) {
    if (ch == '-') break;
    if (ch >= '0' && ch <= '9') break;
    ch = getchar();
  }
  if (ch == '-')
    minus1 = true;
  else
    result = ch - '0';
  while (true) {
    ch = getchar();
    if (ch < '0' || ch > '9') break;
    result = result * 10 + (ch - '0');
  }
  if (minus1)
    return -result;
  else
    return result;
}
bool owiru[MAXN];
int main() {
  string a;
  cin >> a;
  int n = a.size();
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      if (a[i] != a[i + 1]) {
        owiru[i] = 1;
      }
    } else if (i == n - 1) {
      if (a[i] != a[i - 1]) {
        owiru[i] = 1;
      }
    } else {
      if (a[i] != a[i - 1]) {
        owiru[i] = 1;
      }
      if (a[i] != a[i + 1]) {
        owiru[i] = 1;
      }
    }
  }
  string new_str = "";
  vector<pair<int, char>> vec;
  vec.push_back({0, 0});
  for (int i = 0; i < n; i++) {
    if (!owiru[i]) {
      vec[vec.size() - 1] = {vec[vec.size() - 1].first + 1, a[i]};
      new_str += a[i];
    }
    if (owiru[i]) {
      vec.push_back({0, 0});
      ans = 1;
    }
  }
  if (!ans) {
    cout << ans;
    return 0;
  }
  vector<pair<int, char>> new_vec;
  for (pair<int, char> i : vec) {
    if (i.first != 0) {
      new_vec.push_back(i);
    }
  }
  while (1) {
    if (new_vec.size() <= 1) {
      break;
    }
    for (int i = 0; i < new_vec.size() - 1; i++) {
      if (new_vec[i].second == new_vec[i + 1].second) {
        new_vec[i] = {new_vec[i + 1].first + new_vec[i].first,
                      new_vec[i + 1].second};
        new_vec.erase(new_vec.begin() + i + 1);
        i--;
        continue;
      }
    }
    if (new_vec.size() <= 1) {
      break;
    }
    int mn = MOD;
    for (int i = 0; i < new_vec.size() - 1; i++) {
      mn = min(mn, min(new_vec[i].first, new_vec[i + 1].first));
    }
    bool kek = 0;
    for (int i = 1; i < new_vec.size() - 1; i++) {
      if (mn == new_vec[i].first) {
        kek = 1;
      }
    }
    if (kek == 1) {
      mn = (mn + 1) / 2;
    }
    for (int i = 0; i < new_vec.size(); i++) {
      if (i != 0 && i != new_vec.size() - 1) {
        if (new_vec[i].first - 2 * mn <= 0) {
          new_vec.erase(new_vec.begin() + i);
          i--;
        } else {
          new_vec[i].first -= 2 * mn;
        }
      } else {
        if (new_vec[i].first - mn <= 0) {
          new_vec.erase(new_vec.begin() + i);
          i--;
        } else {
          new_vec[i].first -= mn;
        }
      }
    }
    ans += mn;
  }
  cout << ans;
  return 0;
}
