#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  vector<int> v;
  for (int i = 0; i < S.length(); i++) {
    for (int j = i + 1; j < S.length(); j++) {
      string s1 = S.substr(i, j);
      int count = 0;
      int count1 = 0;
      int count2 = 0;
      int max;
      for (int k = 0; k < s1.length(); k++) {
        if (s1[k] == '0') count = count + 1;
        if (s1[k] == '1') count1 = count1 + 1;
        if (s1[k] == '?') count2 = count2 + 1;
      }
      for (int l = 0; l < s1.length(); l++) {
        if (count > count1) {
          max = count2 + count - count1;
        } else {
          max = count2 + count1 - count;
        }
      }
      v.push_back(max);
    }
  }
  sort(v.begin(), v.end());
  cout << v[2];
}
