#include <bits/stdc++.h>
using uint = unsigned int;
using cat = long long;
using dbl = long double;
constexpr dbl pi = 3.14159265358979323846;
using namespace std;
template <typename T>
T abs(T x) {
  return (x < 0) ? -x : x;
}
cat pw(cat a, cat e, cat mod) {
  if (e <= 0) return 1;
  cat x = pw(a, e / 2, mod);
  x = x * x % mod;
  return (e & 1) ? x * a % mod : x;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  int N = S.length();
  int D_mi = 0, D_mx = N;
  while (D_mx - D_mi > 1) {
    int D = (D_mi + D_mx) / 2;
    int L = -D, R = 0;
    bool ok = true;
    for (int i = 0; i < N; i++) {
      int L_n[2], R_n[2];
      if (S[i] == '1' || S[i] == '?') {
        if (L < 0) {
          L_n[0] = L + 1;
          R_n[0] = R + 1;
          while (L_n[0] <= R_n[0] && R_n[0] > 0) R_n[0]++;
        } else
          L_n[0] = 1, R_n[0] = 0;
      } else
        L_n[0] = 1, R_n[0] = 0;
      if (S[i] == '0' || S[i] == '?') {
        if (R + D > 0) {
          L_n[1] = L - 1;
          R_n[1] = R - 1;
          while (L_n[1] <= R_n[1] && L_n[1] + D < 0) L_n[1]++;
        } else
          L_n[1] = 1, R_n[1] = 0;
      } else
        L_n[1] = 1, R_n[1] = 0;
      if (L_n[0] > R_n[0] && L_n[1] > R_n[1]) {
        ok = false;
        break;
      } else if (L_n[0] > R_n[0]) {
        L = L_n[1];
        R = R_n[1];
      } else if (L_n[1] > R_n[1]) {
        L = L_n[0];
        R = R_n[0];
      } else {
        L = min(L_n[0], L_n[1]);
        R = max(R_n[0], R_n[1]);
      }
    }
    if (!ok)
      D_mi = D;
    else
      D_mx = D;
  }
  cout << D_mx << "\n";
}
