#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll Z = -1000000;
  string s;
  cin >> s;
  ll rui = 0;
  ll a = 0;
  ll f = -1000000;
  for (ll i = 0; i < s.size(); i++) {
    if (s.at(i) == '1') {
      a++;
    } else {
      a--;
    }
    Z = max(Z, a);
  }
  for (ll i = 0; i < s.size(); i++) {
    if (s.at(i) == '1') {
      rui++;
    } else if (s.at(i) == '0') {
      rui--;
    } else {
      if (rui + 1 <= Z) {
        rui++;
      } else {
        rui--;
      }
    }
    f = min(f, rui);
  }
  ll Z1 = Z + 1;
  ll f1 = -1000000;
  rui = 0;
  for (ll i = 0; i < s.size(); i++) {
    if (s.at(i) == '1') {
      rui++;
    } else if (s.at(i) == '0') {
      rui--;
    } else {
      if (rui + 1 <= Z1) {
        rui++;
      } else {
        rui--;
      }
    }
    f1 = min(f1, rui);
  }
  ll ans = min(Z - f, Z + 1 - f1);
  cout << ans << endl;
}
