#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 1000006;
int n;
char a[N];
void solv() {
  scanf(" %s", a);
  n = strlen(a);
  int minu = 0, maxu = 0;
  int ans = 1;
  for (int i = 0; i < n; ++i) {
    if (a[i] == '0') {
      --minu;
      --maxu;
    } else if (a[i] == '1') {
      ++minu;
      ++maxu;
    } else {
      ++minu;
      --maxu;
      minu = min(0, minu);
      maxu = max(0, maxu);
    }
    ans = max(ans, max(abs(minu), abs(maxu)));
  }
  printf("%d\n", ans);
}
int main() {
  solv();
  return 0;
}
