#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int a[2] = {0, 0};
  int sol = 0;
  for (int i = 0; i < 2; ++i) {
    int res = 0, best = 0;
    int p = 0;
    for (auto x : s) {
      p++;
      int u = x == '?' ? i : x - '0';
      u = 2 * u - 1;
      if (i == 1) u *= -1;
      res = max(res + u, 0);
      if (x != '?' && (x - '0') != i) {
        best = max(best, res);
      }
      if (x != '?') {
        a[p & 1] |= 1 << (x - '0');
      }
    }
    sol = max(sol, best);
  }
  if (a[0] > a[1]) swap(a[0], a[1]);
  if (a[1] == 0 || (a[0] < a[1] && a[1] < 3)) {
    cout << 1 << '\n';
  } else {
    cout << max(sol, 2) << '\n';
  }
  return 0;
}
