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