#include <bits/stdc++.h>
using namespace std;
long long int calc(string s, long long int f) {
  long long int c = 0, ans = 0, n = s.size(), pre = f;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0')
      c--, pre = -1;
    else if (s[i] == '1')
      c++, pre = 1;
    else {
      if (c > 0) {
        c--;
        pre = -1;
      } else if (c < 0) {
        c++;
        pre = 1;
      } else {
        c += pre * -1;
        pre *= -1;
      }
    }
    ans = max(ans, abs(c));
  }
  return ans;
}
int main(int argc, char const *argv[]) {
  string s;
  std::cin >> s;
  std::cout << min(calc(s, 1), calc(s, -1)) << '\n';
  return 0;
}
