#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  string s;
  cin >> s;
  int n = s.size();
  bool is1 = false;
  for (int z = 0; z < (int)(2); ++z) {
    bool ok = true;
    for (int i = 0; i < (int)(n); ++i) ok &= s[i] != (char)('0' + (i + z) % 2);
    is1 |= ok;
  }
  if (is1)
    cout << 1 << '\n';
  else {
    int ans = 2;
    for (int z = 0; z < (int)(2); ++z) {
      int b = 0, minb = 0;
      for (int i = 0; i < (int)(n); ++i) {
        if (s[i] == (char)('0' + z))
          ++b;
        else
          --b;
        uin(minb, b);
        uax(ans, b - minb);
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
