#include <bits/stdc++.h>
using namespace std;
const long long MAXVAL = (long long)1e18 + 1;
const long long MOD = 1000000007;
const int INF = 1000000000 + 1;
long long poww(int x, long long pow) {
  if (pow == 0ll) return 1;
  if (pow == 1ll) return x % MOD;
  long long ans = poww(x, pow >> 1) % MOD;
  ans = (ans * ans) % MOD;
  if ((pow & 1) == 1) {
    ans = (ans * x) % MOD;
  }
  return ans % MOD;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
  while (q-- > 0) {
    string s;
    cin >> s;
    int n = s.length();
    int curans = n + 1;
    int f[n + 1];
    f[0] = 0;
    int curmin = 0;
    int curmax = 0;
    for (int i = 1; i <= n; ++i) {
      if (s[i - 1] == '0') {
        f[i] = f[i - 1] - 1;
        curmin = min(curmin, f[i]);
        curmax = max(curmax, f[i]);
      } else if (s[i - 1] == '1') {
        f[i] = f[i - 1] + 1;
        curmin = min(curmin, f[i]);
        curmax = max(curmax, f[i]);
      } else {
        int val1 = f[i - 1] - min(0, curmin);
        int val2 = f[i - 1] - max(0, curmax);
        bool one = false;
        if (max(abs(val1 + 1), abs(val2 + 1)) <=
            max(abs(val1 - 1), abs(val2 - 1))) {
          one = true;
        } else
          one = false;
        if (one) {
          f[i] = f[i - 1] + 1;
        } else {
          f[i] = f[i - 1] - 1;
        }
        curmin = min(curmin, f[i]);
        curmax = max(curmax, f[i]);
      }
    }
    int ans = max(abs(curmin), abs(curmax));
    cout << ans << endl;
  }
  return 0;
}
