#include <bits/stdc++.h>
int main() {
  char S[1000001];
  int zero = 0, one = 0, O = 0, I = 0, OUT;
  int max = 0, M = 0;
  scanf("%s", S);
  if (S[0] == '0') {
    zero++;
    O++;
  } else if (S[0] == '1') {
    one++;
    I++;
  } else {
    if (S[1] != '0')
      zero++;
    else
      one++;
  }
  if (zero > one)
    max = zero - one;
  else
    max = one - zero;
  if (M < max) M = max;
  for (int i = 1; i < strlen(S); i++) {
    if (S[i] == '0') {
      zero++;
      O++;
    } else if (S[i] == '1') {
      one++;
      I++;
    } else {
      if (zero > one)
        one++;
      else
        zero++;
    }
    if (zero > one)
      max = zero - one;
    else
      max = one - zero;
    if (M < max) M = max;
  }
  if (O > I)
    OUT = O - I;
  else
    OUT = I - O;
  if (M < OUT)
    printf("%d\n", M);
  else
    printf("%d\n", OUT);
  return 0;
}
