#include <bits/stdc++.h>
using namespace std;
int maximum(string s, int mx, int n) {
  int o = 0, z = 0, i, j;
  for (i = 0; i <= mx; i++) {
    z += (s[i] == '0');
    o += (s[i] == '1');
  }
  int lft = 0;
  for (i = 0; i < n; i++) {
    if (i > mx) {
      o -= (s[lft] == '1');
      z -= (s[lft] == '0');
      lft++;
      mx = max(mx, abs(o - z));
    }
    if (s[i] == '?') {
      if (o < z) {
        o++;
        s[i] = '1';
      } else {
        z++;
        s[i] = '0';
      }
      mx = max(mx, abs(o - z));
    }
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string s, second;
  cin >> s;
  second = s;
  reverse(second.begin(), second.end());
  int n = s.size(), i, j, o = 0, z = 0, q = 0;
  for (i = 0; i < n; i++) {
    o += (s[i] == '1');
    z += (s[i] == '0');
  }
  int mx = abs(o - z);
  if (mx == n) return cout << mx << endl, 0;
  cout << min(maximum(s, mx, n), maximum(second, mx, n)) << endl;
}
