#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int ans = 0;
  int counter = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '(') {
      counter += 1;
    } else if (s[i] == ')') {
      if (counter > 0) {
        ans += 2;
        counter -= 1;
      }
    }
  }
  cout << ans << endl;
}
