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