#include <bits/stdc++.h>
using namespace std;
int main() {
  string brackets;
  cin >> brackets;
  int counter = 0;
  int answer = brackets.length();
  for (int i = 0; i < brackets.length(); i++) {
    if (brackets[i] == '(') {
      counter++;
    } else if (brackets[i] == ')') {
      counter--;
    }
    if (counter < 0) {
      answer--;
      counter++;
    }
  }
  answer -= counter;
  cout << answer << endl;
}
