#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 11;   string s;   bool vis[maxn];   int n;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> s;     n = s.length();     vector<pair<int, int> > vec, tmp;     for (int i = 0; i < n; i++) {       if (vec.empty() || s[vec.back().first] != s[i])         vec.emplace_back(i, i);       else {         pair<int, int> p = vec.back();         vec.pop_back();         vec.emplace_back(p.first, i);       }     }     int ans = 0;     while (vec.size() > 1) {       for (int i = 0; i < (int)(vec).size(); i++) {         int sub = 2 - (i == 0 || i == (int)(vec).size() - 1);         if (vec[i].second >= vec[i].first + sub) {           if (tmp.empty() || s[tmp.back().first] != s[vec[i].first]) {             vec[i].second -= sub;             tmp.push_back(vec[i]);           } else {             pair<int, int> p = tmp.back();             tmp.pop_back();             p.second += vec[i].second - vec[i].first + 1 - sub;             tmp.push_back(p);           }         }       }       ans++;       tmp.swap(vec);       tmp.clear();     }     cout << ans << endl;     return 0;   }   