#include <bits/stdc++.h>
using namespace std;
long long readi() {
  long long input = 0;
  char c = ' ';
  while (c < '-') {
    c = getchar();
  }
  bool negative = false;
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  while (c >= '0') {
    input = 10 * input + (c - '0');
    c = getchar();
  }
  if (negative) {
    input = -input;
  }
  return input;
}
void printi(long long output) {
  if (output == 0) {
    putchar('0');
    return;
  }
  if (output < 0) {
    putchar('-');
    output = -output;
  }
  int aout[20];
  int ilen = 0;
  while (output) {
    aout[ilen] = ((output % 10));
    output /= 10;
    ilen++;
  }
  for (int i = ilen - 1; i >= 0; i--) {
    putchar(aout[i] + '0');
  }
  return;
}
string reads() {
  string input = "";
  char c = ' ';
  while (c <= ' ') {
    c = getchar();
  }
  while (c > ' ') {
    input += c;
    c = getchar();
  }
  return input;
}
int sgn(long long x) {
  if (x < 0) {
    return -1;
  }
  if (x > 0) {
    return 1;
  }
  return 0;
}
long long randomize(long long mod) {
  return ((1 << 30) * rand() + (1 << 15) * rand() + rand()) % mod;
}
const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-30;
long long normalize(long long x, long long mod) {
  return (((x % mod) + mod) % mod);
}
string s;
int N;
int arr[1000010];
vector<pair<int, int> > blocks, active;
int SZ;
int ans;
int32_t main() {
  ios_base::sync_with_stdio(0);
  srand(time(0));
  if (fopen("cf909d.in", "r")) {
    freopen("cf909d.in", "r", stdin);
    freopen("cf909d.out", "w", stdout);
  }
  cin >> s;
  N = s.length();
  for (int i = 0; i < s.length(); i++) {
    arr[i] = s[i] - 'a' + 1;
  }
  for (int i = 0; i < N; i++) {
    SZ++;
    if (i == N - 1 || arr[i] != arr[i + 1]) {
      blocks.push_back(make_pair(arr[i], SZ));
      SZ = 0;
    }
  }
  while (blocks.size() > 1) {
    int t = 1000000007;
    for (int i = 0; i < blocks.size(); i++) {
      if (i == 0 || i == blocks.size() - 1) {
        t = min(t, blocks[i].second);
      } else {
        t = min(t, (blocks[i].second + 1) / 2);
      }
    }
    for (int i = 0; i < blocks.size(); i++) {
      if (i == 0 || i == blocks.size() - 1) {
        blocks[i].second -= t;
      } else {
        blocks[i].second -= 2 * t;
      }
      if (blocks[i].second <= 0) {
        continue;
      }
      if (!active.empty() && blocks[i].first == active.back().first) {
        active.back().second += blocks[i].second;
      } else {
        active.push_back(blocks[i]);
      }
    }
    blocks.clear();
    for (int i = 1; i < active.size(); i++) {
      if (active[i].first == active[i - 1].first) {
        active[i].second += active[i - 1].second;
        active[i - 1].second = 0;
      }
    }
    for (int i = 0; i < active.size(); i++) {
      if (active[i].second) {
        blocks.push_back(active[i]);
      }
    }
    active.clear();
    ans += t;
  }
  cout << ans << '\n';
}
