#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
int n;
char s[maxn + 5];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  int l = 0, r = 0, k = 0;
  for (int i = (n); i >= int(1); i--) {
    int L1, R1, K1, L2, R2, K2;
    if (l == 0 && r == 0)
      L1 = R1 = 0, K1 = k + 1;
    else if (r == 0)
      L1 = l + 1, R1 = r, K1 = k;
    else
      L1 = l + 1, R1 = r + 1, K1 = k;
    if (l == -k && r == -k)
      K2 = k + 1, L2 = R2 = -K2;
    else if (l == -k)
      L2 = l, R2 = r - 1, K2 = k;
    else
      L2 = l - 1, R2 = r - 1, K2 = k;
    if (s[i] == '0') {
      l = L1, r = R1, k = K1;
    } else if (s[i] == '1') {
      l = L2, r = R2, k = K2;
    } else {
      if (K1 < K2)
        l = L1, r = R1, k = K1;
      else if (K1 > K2)
        l = L2, r = R2, k = K2;
      else
        l = min(L1, L2), r = max(R1, R2), k = K1;
    }
  }
  printf("%d\n", k);
  return 0;
}
