#include <bits/stdc++.h>
char s[(int long long unsigned)(1e6 + 23)];
int long long unsigned l, r;
int main(int argn, char **args) {
  std::scanf("%s", s);
  for (int long long unsigned k(0); s[k];) switch (s[k++]) {
      case '(':
        ++r, ++l;
        break;
      case ')':
        if (r) --r, ++l;
        break;
    };
  l -= r;
  std::printf("%I64u", l);
  return 0;
}
