#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
const int INF = 1e9;
bool valid(const string& s, int lim) {
  const int olim = lim - (1 - lim % 2), elim = lim - (lim % 2);
  int olo = 1, ohi = olim;
  int elo = 0, ehi = elim;
  for (char c : s) {
    swap(olo, elo);
    swap(ohi, ehi);
    if (c == '0' || c == '?') {
      olo = max(1, olo - 1);
      elo = max(0, elo - 1);
    } else {
      olo++;
      if (olo > lim) olo = INF;
      elo++;
      if (elo > lim) elo = INF;
    }
    if (c == '1' || c == '?') {
      ohi = min(olim, ohi + 1);
      ehi = min(elim, ehi + 1);
    } else {
      ohi--;
      if (ohi < 0) ohi = -INF;
      ehi--;
      if (ehi < 0) ehi = -INF;
    }
  }
  return olo <= ohi || elo <= ehi;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int lo = 0, hi = s.size();
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    if (valid(s, mid)) {
      hi = mid;
    } else {
      lo = mid + 1;
    }
  }
  cout << lo << endl;
  return 0;
}
