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