#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1000000007LL;
const int N = 2e5 + 10;
const long long Inf = 2242545357980376863LL;
const long long Log = 30;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  int L = -1, R = n + 3;
  int mid;
  int l, r;
  while (L + 1 < R) {
    mid = (L + R) >> 1;
    l = 0, r = mid;
    bool fl = true;
    for (auto &c : s) {
      if (c == '0') {
        l--;
        r--;
      }
      if (c == '1') {
        l++;
        r++;
      }
      if (c == '?') {
        l--;
        r++;
      }
      l = max(l, 0);
      r = min(r, mid);
      if (l > r) fl = false;
    }
    if (fl)
      R = mid;
    else
      L = mid;
  }
  cout << R << '\n';
  return 0;
}
