#include <bits/stdc++.h>
using namespace std;
int t;
vector<int> q = vector<int>();
void test(string S, unsigned int i) {
  if (i == q.size()) {
    long Sp = stol(S, 0, 2);
    int te = 0;
    for (unsigned int l = 0; l < S.size(); l++) {
      for (unsigned int r = l; r < S.size(); r++) {
        int ti;
        for (int j = l; j <= r; j++) {
          if ((Sp >> j) & 1)
            ti++;
          else
            ti--;
        }
        te = max(te, abs(ti));
      }
    }
    t = min(t, te);
  } else {
    S.at(q.at(i)) = '0';
    test(S, i + 1);
    S.at(q.at(i)) = '1';
    test(S, i + 1);
  }
}
int main() {
  string S;
  cin >> S;
  t = S.size();
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == '?') q.push_back(i);
  }
  test(S, 0);
  cout << t << endl;
}
