#include <bits/stdc++.h>
int main() {
  int n, i, j = 0, curr = 0;
  char ch[1000002];
  scanf("%s", &ch);
  n = strlen(ch);
  for (i = 0; i < n; i++) {
    if (ch[i] == '(')
      curr++;
    else if (ch[i] == ')' && curr > 0) {
      curr--;
      j++;
    }
  }
  printf("%d", 2 * j);
  return 0;
}
