#include <bits/stdc++.h>
using namespace std;
const int N = 1000005, p = 998244353, inf = 0x3f3f3f3f;
int read() {
  int f = 1, g = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) g = g * 10 + ch - '0';
  return f * g;
}
int n, g[N], ans;
char ch[N];
int work(int R) {
  int t = 0, cur = 0;
  for (int i = 1; i <= n; i++) {
    if (ch[i] != '?')
      cur += (ch[i] == '1') ? 1 : -1;
    else
      cur += (cur + 1 + g[i + 1] <= R) ? 1 : -1;
    t = min(t, cur);
  }
  return t;
}
int main() {
  scanf("%s", ch + 1);
  n = strlen(ch + 1);
  for (int i = n; i; i--) g[i] = max(0, g[i + 1] + (ch[i] == '1') ? 1 : -1);
  ans = min(g[1] - work(g[1]), g[1] + 1 - work(g[1] + 1));
  printf("%d\n", ans);
  return 0;
}
