#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = (int)s.size();
  vector<int> L0(n);
  vector<int> L1(n);
  vector<int> R0(n);
  vector<int> R1(n);
  int ans = 0;
  {
    int b = 0;
    for (int i = 0; i < n; i++) {
      L0[i] = b;
      if (s[i] == '0') {
        b += 1;
      } else {
        b = max(b - 1, 0);
      }
      ans = max(ans, b);
    }
  }
  {
    int b = 0;
    for (int i = 0; i < n; i++) {
      L1[i] = b;
      if (s[i] == '1') {
        b += 1;
      } else {
        b = max(b - 1, 0);
      }
      ans = max(ans, b);
    }
  }
  {
    int b = 0;
    for (int i = n - 1; i >= 0; i--) {
      R0[i] = b;
      if (s[i] == '0') {
        b += 1;
      } else {
        b = max(b - 1, 0);
      }
      ans = max(ans, b);
    }
  }
  {
    int b = 0;
    for (int i = n - 1; i >= 0; i--) {
      R1[i] = b;
      if (s[i] == '1') {
        b += 1;
      } else {
        b = max(b - 1, 0);
      }
      ans = max(ans, b);
    }
  }
  for (int i = 0; i < n; i++) {
    if (L0[i] == R1[i]) {
      ans = max(ans, L0[i] + 1);
    }
    if (L1[i] == R0[i]) {
      ans = max(ans, L1[i] + 1);
    }
  }
  if (ans == 1) {
    bool can_be_1 = false;
    {
      bool ok = true;
      for (int i = 0; i < n; i++) {
        if (i % 2 == 0 && s[i] == '1') {
          ok = false;
        }
        if (i % 2 == 1 && s[i] == '0') {
          ok = false;
        }
      }
      can_be_1 |= ok;
    }
    {
      bool ok = true;
      for (int i = 0; i < n; i++) {
        if (i % 2 == 0 && s[i] == '0') {
          ok = false;
        }
        if (i % 2 == 1 && s[i] == '1') {
          ok = false;
        }
      }
      can_be_1 |= ok;
    }
    if (!can_be_1) {
      ans = 2;
    }
  }
  cout << ans << '\n';
  return 0;
}
