#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int in = 0, i, n, count = 0;
  n = s.length();
  for (i = 0; i < n; i++) {
    if (s[i] == '(') in++;
    if (s[i] == ')' && in > 0) {
      in--;
      count++;
    }
  }
  cout << count * 2;
  return 0;
}
