#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
#define fst first
#define snd second
const int INF = 1e9;

bool valid(const string& s, int lim) {
//  cerr << "> lim = " << lim << endl;

  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;
    }

//    fprintf(stderr, ">> odd: [%d, %d], even: [%d, %d]\n", olo, ohi, elo, ehi);
  }

  return olo <= ohi || elo <= ehi;
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  string s; cin >> s;
  int lo = 1, 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;
}
