#include <bits/stdc++.h>
using namespace std;
int main() {
  long int a, b = 0, c, sum = 0;
  string A;
  cin >> A;
  for (a = 0; a < A.length(); a++) {
    if (A[a] == '(') {
      b++;
    } else {
      if (b >= 1) {
        sum = sum + 2;
        b--;
      }
    }
  }
  cout << sum << endl;
}
