#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int left = 0, right = s.size();
  while (left < right) {
    int mid = (left + right) / 2;
    int next1 = mid;
    int next0 = mid;
    int flag = true;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        next1--;
        next0++;
      } else if (s[i] == '0') {
        next1++;
        next0--;
      } else {
        if (next1 == 0) {
          next1++;
          next0--;
        } else if (next0 == 0) {
          next0++;
          next1--;
        } else {
          next1++;
          next0++;
        }
      }
      if (next0 < 0 || next1 < 0) {
        flag = false;
        break;
      }
      next1 = min(next1, mid);
      next0 = min(next0, mid);
    }
    if (flag) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  cout << left << endl;
}
