#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
int mx, n, a[100010], b[100010];
char s[100010];
void init() {
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    sum += (s[i] == '1' ? 1 : -1);
    mx = max(mx, sum);
    a[i] = sum;
  }
  b[n] = a[n];
  for (int i = n - 1; i >= 0; --i) {
    b[i] = max(a[i], b[i + 1]);
  }
}
int calc(int lim) {
  int mn = 0, sum = 0;
  for (int i = 1; i <= n; ++i) {
    if (s[i] == '1')
      ++sum;
    else if (s[i] == '0')
      --sum;
    else {
      if (b[i] - a[i - 1] + sum + 2 <= lim)
        ++sum;
      else
        --sum;
    }
    mn = min(mn, sum);
  }
  return mn;
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  init();
  printf("%d\n", min(mx - calc(mx), mx + 1 - calc(mx + 1)));
  return 0;
}
