#include <bits/stdc++.h>
#pragma warning(disable : 4996)
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);
      if (un < avsolute(strchnum(ss, '1') - strchnum(ss, '0'))) {
        un = avsolute(strchnum(ss, '1') - strchnum(ss, '0'));
      }
    }
  }
  return un;
}
int main() {
  char* s = (char*)malloc(sizeof(char) * 1000000);
  scanf("%s", s);
  int on = strchnum(s, '1'), ze = strchnum(s, '0'), q = strchnum(s, '?');
  for (int i = 0; i != q; i++) {
    char* cp = strchr(s, '?');
    *cp = (strchnum(s, '1') < strchnum(s, '0')) ? '1' : '0';
  }
  printf("%d", unbalance(s));
  return 0;
}
