#include <bits/stdc++.h>
using namespace std;
long long __abs(long long xx, long long yy) {
  if (xx > yy) {
    return (xx - yy);
  }
  return (yy - xx);
}
int main() {
  string ss;
  cin >> ss;
  long long memo = 0, min = 0, max = 0;
  bool flag = true;
  for (long long ii = 0; ii < ss.length(); ii++) {
    if (ss[ii] != '?') {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << '1' << endl;
    return 0;
  }
  for (long long ii = 0; ii < ss.length(); ii++) {
    if (ss[ii] == '1') {
      memo++;
    } else if (ss[ii] == '0') {
      memo--;
    } else {
      if (memo < 0) {
        memo++;
        ss[ii] = '1';
      } else if (memo > 0) {
        memo--;
        ss[ii] = '0';
      } else if (__abs(max, memo) > __abs(min, memo)) {
        memo++;
        ss[ii] = '1';
      } else if (__abs(max, memo) < __abs(min, memo)) {
        memo--;
        ss[ii] = '0';
      }
    }
  }
  memo = 0;
  for (long long ii = ss.length() - 1; ii >= 0; ii--) {
    if (ss[ii] == '1') {
      memo++;
    } else if (ss[ii] == '0') {
      memo--;
    } else {
      if (memo < 0) {
        memo++;
        ss[ii] = '1';
      } else if (memo > 0) {
        memo--;
        ss[ii] = '0';
      } else if (__abs(max, memo) > __abs(min, memo)) {
        memo++;
        ss[ii] = '1';
      } else if (__abs(max, memo) < __abs(min, memo)) {
        memo--;
        ss[ii] = '0';
      }
    }
    if (memo > max) {
      max = memo;
    }
    if (memo < min) {
      min = memo;
    }
  }
  cout << __abs(max, min) << endl;
  return 0;
}
