#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 L = 0, R = 0, D = 0;
  for (int i = 0; i < N; i++) {
    int L_n[2], R_n[2], D_n[2];
    if (S[i] == '1' || S[i] == '?') {
      if (L < 0) {
        D_n[0] = D;
        L_n[0] = L + 1;
        R_n[0] = R + 1;
        if (R == 0) R_n[0] -= 2;
      } else {
        D_n[0] = D + 1;
        L_n[0] = R_n[0] = 0;
      }
    } else
      D_n[0] = N + 1;
    if (S[i] == '0' || S[i] == '?') {
      if (R + D > 0) {
        D_n[1] = D;
        L_n[1] = L - 1;
        R_n[1] = R - 1;
        if (L + D == 0) L_n[1] += 2;
      } else {
        D_n[1] = D + 1;
        L_n[1] = R_n[1] = -D - 1;
      }
    } else
      D_n[1] = N + 1;
    if (D_n[0] > D_n[1]) {
      D = D_n[1];
      L = L_n[1];
      R = R_n[1];
    } else if (D_n[0] < D_n[1]) {
      D = D_n[0];
      L = L_n[0];
      R = R_n[0];
    } else {
      D = D_n[0];
      L = min(L_n[0], L_n[1]);
      R = max(R_n[0], R_n[1]);
    }
  }
  cout << D << "\n";
}
