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