#include <bits/stdc++.h>
using namespace std;
int main() {
  string input;
  cin >> input;
  int openBrackets = 0;
  int sequenceLength = 0;
  for (auto i : input) {
    if (i == '(') {
      openBrackets++;
    } else if (openBrackets) {
      openBrackets--;
      sequenceLength += 2;
    }
  }
  cout << sequenceLength << endl;
  return 0;
}
