#include <bits/stdc++.h>
using namespace std;
char s[2000010];
int sum[2000010], N, mx[2000010];
int calc(int x) {
  int p = 0;
  for (int i = 1; i <= N; i++) {
    if (s[i] == '1')
      sum[i] = sum[i - 1] + 1;
    else if (s[i] == '0')
      sum[i] = sum[i - 1] - 1;
    else {
      if (mx[i] + 2 * (p + 1) <= x) {
        sum[i] = sum[i - 1] + 1, p++;
      } else
        sum[i] = sum[i - 1] - 1;
    }
  }
  int mn = N;
  for (int i = 1; i <= N; i++) mn = min(mn, sum[i]);
  return mn;
}
int main() {
  scanf("%s", s + 1);
  N = strlen(s + 1);
  for (int i = 1; i <= N; i++) {
    if (s[i] == '1') {
      sum[i] = sum[i - 1] + 1;
    } else
      sum[i] = sum[i - 1] - 1;
  }
  mx[N] = sum[N];
  for (int i = N - 1; i >= 0; i--) mx[i] = max(mx[i + 1], sum[i]);
  int m = mx[0];
  printf("%d\n", min(m - calc(m), m + 1 - calc(m + 1)));
  return 0;
}
