#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
class B01Unbalanced {
 public:
  void solve(istream& cin, ostream& cout) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    int n = s.size();
    int cnt = 0;
    int ma = 0;
    vector<int> ZL(n), ZR(n), OL(n), OR(n);
    bool flag = true;
    for (int i = 0; i < n; i++) {
      if (i % 2 == 0) {
        if (s[i] == '1') flag = false;
      } else {
        if (s[i] == '0') flag = false;
      }
    }
    if (flag) {
      cout << 1 << endl;
      return;
    }
    flag = true;
    for (int i = 0; i < n; i++) {
      if (i % 2 != 0) {
        if (s[i] == '1') flag = false;
      } else {
        if (s[i] == '0') flag = false;
      }
    }
    if (flag) {
      cout << 1 << endl;
      return;
    }
    ma = 2;
    for (int i = 0; i < (int)(n); i++) {
      if (s[i] == '1') {
        cnt++;
      } else {
        cnt--;
        chmax(cnt, 0);
      }
      chmax(ma, cnt);
      OL[i] = cnt;
    }
    cnt = 0;
    for (int i = 0; i < (int)(n); i++) {
      if (s[i] == '0') {
        cnt++;
      } else {
        cnt--;
        chmax(cnt, 0);
      }
      chmax(ma, cnt);
      ZL[i] = cnt;
    }
    cnt = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (s[i] == '1') {
        cnt++;
      } else {
        cnt--;
        chmax(cnt, 0);
      }
      chmax(ma, cnt);
      OR[i] = cnt;
    }
    for (int i = n - 1; i >= 0; i--) {
      if (s[i] == '0') {
        cnt++;
      } else {
        cnt--;
        chmax(cnt, 0);
      }
      chmax(ma, cnt);
      ZR[i] = cnt;
    }
    for (int i = 1; i < n - 1; i++) {
      if (OL[i - 1] == ZR[i + 1]) {
        chmax(ma, OL[i - 1] + 1);
      }
      if (ZL[i - 1] == OR[i + 1]) {
        chmax(ma, ZL[i - 1] + 1);
      }
    }
    cout << ma << endl;
  }
};
signed main() {
  B01Unbalanced solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
