#include <bits/stdc++.h>
#pragma warning(disable : 4996)
int strconti(char* s) {
  if (s == NULL) {
    return -1;
  }
  char c = s[0];
  int i = 1;
  while (1) {
    if (s[i - 1] != c) {
      break;
    }
    i++;
  }
  return i;
}
int strchnum(const char s[], int c) {
  int i;
  int count = 0;
  for (i = 0; s[i] != '\0'; i++)
    if (s[i] == c) count++;
  return (count);
}
int substr(char* t, const char* s, int pos, int len) {
  if (pos < 0 || len < 0 || len > strlen(s)) return -1;
  for (s += pos; *s != '\0' && len > 0; len--) *t++ = *s++;
  *t = '\0';
  return 0;
}
int avsolute(int v) { return v < 0 ? v * -1 : v; }
int unbalance(char* s) {
  int ls = strlen(s);
  int un = 0;
  char* ss = (char*)malloc(sizeof(char) * ls);
  for (int r = 1; r != ls; r++) {
    for (int l = 0; l != r; l++) {
      substr(ss, s, l, r);
      int tmp = avsolute(strchnum(ss, '1') - strchnum(ss, '0'));
      if (un < tmp) {
        un = tmp;
      }
    }
  }
  return un;
}
int main() {
  char* s = (char*)malloc(sizeof(char) * 1000000);
  scanf("%s", s);
  int q = strchnum(s, '?');
  int on = strchnum(s, '1');
  int ze = strchnum(s, '0');
  char c = (on > ze) ? '1' : '0';
  int a = avsolute(on - ze);
  int b = (q - a) / 2;
  for (int i = 0; i != q; i++) {
    char* cp = strchr(s, '?');
    int d = strconti(cp);
    if (d > 0) {
      d /= 2;
      *(cp + d) = c;
      *cp = (strchnum(s, '1') < strchnum(s, '0')) ? '1' : '0';
    } else {
      break;
    }
  }
  strchnum(s, '1');
  strchnum(s, '0');
  printf("%d", unbalance(s));
  return 0;
}
