#include <bits/stdc++.h>
const long long mod = (long long)1e9 + 7;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int count = 0;
  int cc = 0;
  int cf = 0;
  int ans;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '?') {
      s[i] = 0;
      s[i] = 1;
    }
    if (s[i] == '0') count++;
    if (s[i] == '1') cc++;
    ans = abs(count - cc);
    ans = max(ans, cc);
  }
  cout << ans << "\n";
  return 0;
}
