#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int count1 = 0, l = s.length();
  stack<char> v;
  for (int i = 0; i < l; i++) {
    if (s[i] == '(')
      v.push(s[i]);
    else {
      if (!v.empty()) {
        v.pop();
        count1 += 2;
      }
    }
  }
  cout << count1 << endl;
  return 0;
}
