#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
template <typename first>
inline first abs(const first& a) {
  return a < 0 ? -a : a;
}
template <typename first>
inline first sqr(const first& a) {
  return a * a;
}
using namespace std;
const int N = 1000000 + 13;
char s[N];
int main() {
  gets(s);
  int n = int(strlen(s));
  int ans = 0, bal = 0;
  for (int i = 0; i < int(n); i++) {
    if (s[i] == '(') {
      bal++;
    } else {
      if (bal > 0) bal--, ans++;
    }
  }
  cout << 2 * ans << endl;
  return 0;
}
