#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();
  int ll = 0;
  int rr = 0;
  int mm = 0;
  bool even = true;
  for (char c : s) {
    if (c == '1') {
      ll++;
      rr++;
      if (rr > mm) {
        if (ll > mm) {
          mm++;
        } else {
          rr -= (1 + even);
        }
      }
    } else if (c == '0') {
      ll--;
      rr--;
      if (ll < 0) {
        if (rr < 0) {
          ll++;
          rr++;
          mm++;
        } else {
          ll += (1 + even);
        }
      }
    } else {
      if (mm == 0) {
        mm++;
        rr++;
        even = false;
      } else if (mm == 1) {
        if (ll == rr) {
          ll = 1 - ll;
          rr = 1 - rr;
        }
      } else {
        ll--;
        rr++;
        while (ll < 0) ll += (1 + even);
        while (rr > mm) rr -= (1 + even);
      }
    }
    if (ll == rr) even = true;
  }
  cout << mm << "\n";
  return 0;
}
