#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
char el = '\n';
char esp = ' ';
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
ostream& operator<<(ostream& os, const vector<bool>& v) {
  for (auto const& i : v) {
    os << i << " ";
  }
  os << '\n';
  return os;
}
string yes = "YES";
string no = "NO";
int triangular(int n) { return n * (n + 1) / 2; }
int cl(int a, int b) { return (a + b - 1) / b; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string s;
  cin >> s;
  int n = s.size();
  vector<bool> marked(n);
  vector<bool> visited(n);
  vector<vi> g(n);
  for (int i = 0; i < n - 1; i++) {
    if (s[i] != s[i + 1]) {
      if (!g[i].size()) marked[i] = 1;
      g[i].push_back(i + 1), g[i + 1].push_back(i);
    }
  }
  int ans = 0;
  vector<int> distances(n);
  queue<int> q;
  for (int i = 0; i < n; i++) {
    if (marked[i]) {
      q.push(i);
      marked[i] = 0;
      distances[i] = 1;
    }
  }
  function<int(int)> dfs = [&](int u) {
    visited[u] = 1;
    int sz = 0;
    for (int v : g[u]) {
      if (!visited[v]) {
        sz++;
        sz += dfs(v);
      }
    }
    return sz;
  };
  while (q.size()) {
    int u = q.front();
    q.pop();
    int sz = dfs(u);
    if (u - 1 > -1 && u + sz < n && s[u - 1] != s[u + sz]) {
      g[u - 1].push_back(u + sz), g[u + sz].push_back(u - 1);
      distances[u - 1] = distances[u + sz] = distances[u] + 1;
    }
  }
  cout << *max_element(distances.begin(), distances.end()) << el;
}
