#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  std::cin >> s;
  long long int n = s.size();
  long long int l = 0, r = n;
  while (r - l > 1) {
    bool f = false;
    long long int mid = (l + r) / 2;
    for (int i = 0; i < 2; i++) {
      long long int a = i, b = mid;
      for (int j = 0; j < n; j++) {
        if (s[j] == '1')
          a++, b++;
        else if (s[j] == '0')
          a--, b--;
        else
          a--, b++;
        if (a < 0) a += 2;
        if (b > mid) b -= 2;
        if (b < a) goto nxt;
      }
      f = true;
    nxt:;
    }
    if (f)
      r = mid;
    else
      l = mid;
  }
  std::cout << r << '\n';
  return 0;
}
