#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 1 << 20, mod = 1e9 + 7;
string s;
int n, ans = 1 << 30;
int p[maxn], sm[maxn];
void solvep() {
  p[0] = 0;
  int gm = 0;
  for (int i = 1; i <= n; i++) {
    p[i] = p[i - 1] + (s[i] == '-' ? -1 : 1);
    gm = min(gm, p[i]);
  }
  sm[n] = p[n];
  for (int i = n; i--;) sm[i] = min(p[i], sm[i + 1]);
  for (int r = 0, i = 0; i <= n; i++) {
    sm[i] += r;
    if (s[i] == '?' && sm[i] - 2 >= gm) {
      r -= 2;
      sm[i] -= 2;
    }
  }
  int rm = 0;
  for (int i = 0; i <= n; i++) rm = max(rm, sm[i]);
  ans = min(ans, abs(gm - rm));
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> s;
  n = s.size();
  s = "." + s;
  solvep();
  memset(p, 0, sizeof p);
  memset(sm, 0, sizeof sm);
  for (auto i : s) {
    if (i == '1')
      i = '0';
    else if (i == '0')
      i = '1';
  }
  solvep();
  cout << ans;
}
