#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  stack<char> st;
  string s;
  cin >> s;
  int res = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '(') {
      st.push(s[i]);
    }
    if (s[i] == ')' and st.empty()) {
      continue;
    }
    if (s[i] == ')' and st.top() == '(') {
      res += 2;
      st.pop();
    }
  }
  cout << res << endl;
}
