#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
char s[N + 5];
int n;
int main() {
  int i, k;
  scanf("%s", s);
  n = strlen(s);
  int l = 0, r = n;
  while (l < r) {
    int mid = (l + r) / 2;
    bool ok = false;
    for (k = 0; k < 2; k++) {
      int a = k, b = mid;
      if (a % 2 != b % 2) b--;
      bool ng = false;
      for (i = 0; i < n; i++) {
        if (s[i] == '0') {
          a--;
          b--;
        } else if (s[i] == '1') {
          a++;
          b++;
        } else {
          a--;
          b++;
        }
        if (a < 0) a += 2;
        if (b > mid) b -= 2;
        if (b < a) {
          ng = true;
          break;
        }
      }
      if (!ng) ok = true;
    }
    if (ok)
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d", r);
  return 0;
}
