#include <bits/stdc++.h>
char S[1001001];
int main() {
  scanf("%s", S);
  int l = 0, r = 0;
  while (S[r]) r++;
  while (l + 1 < r) {
    int m = (l + r) / 2;
    int p = 0, q = m;
    bool g = 1;
    for (int i = 0; S[i]; i++) {
      if (S[i] == '0') p++, q++;
      if (S[i] == '1') p--, q--;
      if (S[i] == '?') p--, q++;
      if (p < 0) p = 0;
      if (q > m) q = m;
      if (p > q) g = 0;
    }
    if (g)
      r = m;
    else
      l = m;
  }
  printf("%d\n", r);
  return 0;
}
