#include <bits/stdc++.h>
using namespace std;
char a[1000005];
int main() {
  while (gets(a)) {
    int left = 0;
    int result = 0;
    int n = strlen(a);
    for (int i = 0; i < n; i++) {
      if (a[i] == '(') {
        left++;
      } else {
        if (left > 0) {
          left--;
          result++;
        }
      }
    }
    printf("%d\n", result * 2);
  }
  return 0;
}
