#include <bits/stdc++.h>
using namespace std;
const int mxn = 1000000;
int n;
string second;
int a[mxn], b[mxn];
int sol(int x) {
  int r1 = 0, r2 = 0;
  for (int i = 0; i < n; i++) {
    r2 += 2 * (second[i] == '?' && b[i] + r2 < x - 1);
    r1 = min(r1, a[i] + r2);
  }
  return x - r1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> second;
  n = second.size();
  for (int i = 0; i < n; i++) {
    a[i] = 2 * (second[i] == '1') - 1 + (i ? a[i - 1] : 0);
  }
  for (int i = n - 1; ~i; i--) {
    b[i] = max(a[i], (i < n - 1 ? b[i + 1] : a[i]));
  }
  int v = max(a[0], 0);
  cout << min(sol(v), sol(v + 1)) << '\n';
  return 0;
}
