#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  long long a, b;
  a = 0;
  b = 0;
  int max = 0;
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] == '?') {
      if (a > b) {
        s[i] = '1';
        b++;
      } else {
        s[i] = '0';
        a++;
      }
    } else if (s[i] == '0') {
      a++;
    } else {
      b++;
    }
    if (max < (abs(a - b))) {
      max = (abs(a - b));
    }
  }
  cout << max;
  return 0;
}
