#include <bits/stdc++.h>
using namespace std;
constexpr long long int MOD = 1000000007;
constexpr double EPS = 1e-9;
long long int N, M, K, H, W, L, R;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  N = s.size();
  int range = 200;
  vector<int> dp(N + range + 100, MOD);
  dp[0] = 0;
  int st = 0;
  vector<int> ndp(N + range + 100, MOD);
  for (int i = 0; i < N; i++) {
    int nst = MOD;
    if (s[i] != '0') {
      for (int j = st; j < st + range; j++) {
        if (dp[j] == MOD) continue;
        int box = max(j, dp[j]);
        if (j >= st + 2) box = max(box, dp[j - 2]);
        dp[j] = box;
        ndp[j + 1] = min(ndp[j + 1], dp[j] + (j == dp[j]));
        nst = min(nst, j + 1);
      }
    }
    if (s[i] != '1') {
      for (int j = max(1, st); j <= st + range; j++) {
        if (dp[j] == MOD) continue;
        int box = max(j, dp[j]);
        if (j >= st + 2) box = max(box, dp[j - 2]);
        dp[j] = box;
        ndp[j - 1] = min(ndp[j - 1], dp[j]);
        nst = min(nst, j - 1);
      }
      if (st == 0) {
        ndp[0] = min(ndp[0], dp[0] + 1);
        nst = 0;
      }
    }
    if (s[i] != '0') {
      for (int j = st; j < st + range; j++) {
        if (dp[j] == MOD) continue;
        if (ndp[j + 1] != MOD) dp[j + 1] = ndp[j + 1];
        ndp[j + 1] = MOD;
      }
    }
    if (s[i] != '1') {
      for (int j = max(1, st); j <= st + range; j++) {
        if (dp[j] == MOD) continue;
        if (ndp[j - 1] != MOD) dp[j - 1] = ndp[j - 1];
        ndp[j - 1] = MOD;
      }
      if (st == 0) {
        if (ndp[0] != MOD) dp[0] = ndp[0];
        ndp[0] = MOD;
      }
    }
    st = nst;
  }
  int ans = MOD;
  for (int i = st; i <= st + range; i++) {
    ans = min(ans, max(i, dp[i]));
  }
  cout << ans << endl;
  return 0;
}
