#include <bits/stdc++.h>
using namespace std;
int main() {
  string p;
  cin >> p;
  int count = 0;
  int total = 0;
  int in = p.size();
  for (int i = 0; i < p.size(); i++)
    if (p[i] == '(')
      count++;
    else if (p[i] == ')' && count != 0) {
      count--;
      total += 2;
    }
  cout << total << endl;
}
