#include <bits/stdc++.h>
using namespace std;
namespace Base {
const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
const long long infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
template <typename T>
void read(T &x) {
  x = 0;
  int fh = 1;
  double num = 1.0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  if (ch == '.') {
    ch = getchar();
    while (isdigit(ch)) {
      num /= 10;
      x = x + num * (ch - '0');
      ch = getchar();
    }
  }
  x = x * fh;
}
template <typename T>
void chmax(T &x, T y) {
  x = x < y ? y : x;
}
template <typename T>
void chmin(T &x, T y) {
  x = x > y ? y : x;
}
}  // namespace Base
using namespace Base;
const int N = 1000100;
char s[N];
int f, l, r, n;
int main() {
  scanf("\n%s", s + 1);
  n = strlen(s + 1);
  f = 0, l = 0, r = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '0') {
      l--, r--;
      if (r == f) r -= 2;
      if (l == r) {
        if (l < 0) f++, l++, r++;
      } else if (l <= -2)
        l += 2;
    }
    if (s[i] == '1') {
      l++, r++;
      if (l == 0) l += 2;
      if (l == r) {
        if (r > f) f++, l--, r--;
      } else if (r >= f + 2)
        r -= 2;
    }
    if (s[i] == '?') {
      l--, r++;
      if (l <= -2) l += 2;
      if (r >= f + 2) r -= 2;
    }
  }
  printf("%d\n", f);
  return 0;
}
