#include <bits/stdc++.h>
using namespace std;
int main() {
  string n;
  int count = 0;
  cin >> n;
  stack<char> s;
  for (int i = 0; i < n.length(); i++) {
    if (n[i] == '(') {
      s.push(n[i]);
    } else if (n[i] == ')') {
      if (s.size() != 0) {
        char tops = s.top();
        s.pop();
        if (tops == '(') {
          count += 2;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}
