#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, l = 0, r = 0;
  ;
  char s[1000001];
  while (cin >> s) {
    a = strlen(s);
    l = 0;
    r = 0;
    for (int i = 0; i < a; i++) {
      if (s[i] == '(') l++;
      if (s[i] == ')' && l > 0) {
        l--;
        r++;
      }
    }
    cout << r * 2;
  }
  return 0;
}
