#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T, class U>
void chmin(T& t, const U& u) {
  if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
  if (t < u) t = u;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (int i = 0; i < (v.size()); i++) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}
int main() {
  string S;
  cin >> S;
  V<int> ups(S.size() + 1);
  {
    int u = 0;
    for (int i = int(S.size()) - 1; i >= int(0); i--) {
      if (S[i] == '1') {
        ups[i] = ups[i + 1] + 1;
        u++;
      } else {
        ups[i] = max(ups[i + 1] - 1, 0);
        --u;
      }
      chmax(ups[i], u);
    }
  }
  (void(0));
  auto calc = [&](int ub) {
    int s = 0;
    int mini = 0;
    for (int i = 0; i < (S.size()); i++) {
      char c = S[i];
      if (c == '1') {
        ++s;
      } else if (c == '0') {
        --s;
      } else {
        if (s + 1 + ups[i + 1] <= ub) {
          ++s;
        } else {
          --s;
        }
      }
      chmin(mini, s);
    }
    return ub - mini;
  };
  int maxi = 0;
  {
    int s = 0;
    for (auto c : S) {
      if (c == '(') {
        ++s;
      } else {
        --s;
      }
      chmax(maxi, s);
    }
  }
  (void(0));
  cout << min(calc(maxi), calc(maxi + 1)) << endl;
  return 0;
}
