#include <bits/stdc++.h>
int main(void) {
  int i, j, s0, s1;
  char S[1000000];
  scanf("%s", S);
  j = 1;
  s0 = s1 = 0;
  for (i = 0; i < strlen(S); i++) {
    if (S[i] == '0') s0++;
    if (S[i] == '1') s1++;
    if (S[i] == '?') {
      if (s0 > s1)
        s1++;
      else
        s0++;
    }
    if (abs(s0 - s1) < j) j = abs(s0 - s1);
  }
  printf("%d\n", j);
  return 0;
}
