#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  long int zeros = 0, ones = 0, ans = 0;
  bool chan = false;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0') {
      zeros++;
    } else if (s[i] == '1') {
      ones++;
    } else {
      if (zeros > ones) {
        ones++;
        s[i] = '1';
      } else if (ones > zeros) {
        zeros++;
        s[i] = '0';
      } else {
        if (chan) {
          ones++;
          s[i] = '1';
        } else {
          zeros++;
          s[i] = '0';
        }
        chan = !chan;
      }
    }
    if (ans < abs(zeros - ones)) {
      ans = abs(zeros - ones);
    }
  }
  cout << ans << "\n";
  return 0;
}
