#include <bits/stdc++.h>
int main() {
  using namespace std;
  string S;
  cin >> S;
  unsigned long N{S.size()};
  long lb{0}, ub{0}, nl{0}, nu{0};
  for (unsigned long i{0}; i < N; ++i) {
    if (S[i] == '0') {
      --nl;
      --nu;
      lb = min(lb, nu);
      nl = max(lb, nl);
      if ((nl ^ nu) & 1) ++nl;
    } else if (S[i] == '1') {
      ++nl;
      ++nu;
      ub = max(ub, nl);
      nu = min(ub, nu);
      if ((nl ^ nu) & 1) --nu;
    } else {
      if (ub == lb) {
        ub = nl = nu = 1;
      } else {
        ++nu;
        --nl;
        nl = max(lb, nl);
        if ((nl ^ nu) & 1) ++nl;
        nu = min(ub, nu);
        if ((nl ^ nu) & 1) --nu;
      }
    }
  }
  cout << ub - lb << endl;
  return 0;
}
