#include <bits/stdc++.h>
using namespace std;
int main() {
  int count1 = 0, count2 = 0, w = 0, z = 0, n, p;
  string s;
  cin >> s;
  n = s.length();
  for (int i = 0; i < n; i++) {
    if (s[i] == '1')
      w++;
    else if (s[i] == '0')
      z++;
    else if (s[i] == '?') {
      if (w < z) {
        s[i] = '1';
        w++;
      } else if (z < w) {
        s[i] = '0';
        z++;
      } else {
        if (s[i - 1] == '1') {
          s[i] = '0';
          z++;
        } else {
          s[i] = '1';
          w++;
        }
      }
    }
  }
  int mx = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1')
      count1++;
    else if (s[i] == '0')
      count2++;
    int p = abs(count1 - count2);
    mx = max(mx, p);
  }
  cout << mx << endl;
  return 0;
}
