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