#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int x, i, j, cnt = 0, ans = 0;
  string s;
  cin >> s;
  for (i = 0; i < s.size(); i++) {
    if (s[i] == '(')
      cnt++;
    else {
      if (cnt > 0) {
        cnt--;
        ans += 2;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
