#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    ;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
}
const int N = 205, P = 1e9 + 7, L = 62;
int mul(int a, int b) { return 1ll * a * b % P; }
int sub(int a, int b) {
  a -= b;
  return a < 0 ? a + P : a;
}
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int n;
string s;
bool chk(int x) {
  for (int k = 0; k <= (x); ++k) {
    int w = k, q = 0, fl = 0;
    for (auto c : s) {
      if (c == '0')
        --w;
      else if (c == '1')
        ++w;
      else
        --w, ++q;
      while (w < 0 && q) --q, w += 2;
      if (w < 0 || w > x) fl = 1;
    }
    if (!fl) return true;
  }
  return false;
}
int main(int argc, char *argv[]) {
  cin >> s;
  n = (int)s.size();
  int l = 0, r = n;
  while (r - l > 1) {
    int mid = (l + r) >> 1;
    if (chk(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r << endl;
  return 0;
}
