#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7, INF = 0x3f3f3f3f, sgn[] = {-1, 1};
char a[N];
int n, cnt, maxn, minn, s[N], nxt[N];
int main() {
  scanf("%s", a + 1), n = strlen(a + 1), nxt[n + 1] = -INF;
  for (int i = 1; i <= n; i++) s[i] = s[i - 1] + sgn[a[i] == '1'];
  for (int i = n; i >= 0; i--) nxt[i] = max(nxt[i + 1], s[i]);
  for (int i = 1; i <= n; i++)
    if (a[i] == '?' && cnt + 2 + nxt[i] <= nxt[0]) cnt += 2, a[i] = '1';
  for (int i = 1; i <= n; i++)
    s[i] = s[i - 1] + sgn[a[i] == '1'], maxn = max(maxn, s[i]),
    minn = min(s[i], minn);
  cout << maxn - minn;
  return 0;
}
