#include <bits/stdc++.h>
using namespace std;
string S;
set<pair<long long, long long> > P = {{0, 0}};
long long Res = 1ll << 60;
pair<long long, long long> inc(pair<long long, long long> p) {
  return {min(0ll, p.first + 1), p.second + 1};
}
pair<long long, long long> dec(pair<long long, long long> p) {
  return {p.first - 1, max(0ll, p.second - 1)};
}
int main() {
  cin >> S;
  for (long long i = S.size() - 1; i >= 0; --i) {
    set<pair<long long, long long> > nextP;
    for (auto p : P) {
      if (S[i] != '0') nextP.insert(inc(p));
      if (S[i] != '1') nextP.insert(dec(p));
    }
    P.clear();
    for (auto p : nextP) {
      bool good = true;
      for (auto q : nextP) {
        if (p == q) continue;
        if (p.first <= q.first && q.second <= p.second) {
          good = false;
        }
      }
      if (good) P.insert(p);
    }
  }
  for (auto p : P) {
    Res = min(Res, p.second - p.first);
  }
  cout << Res << endl;
  return 0;
}
