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