#include <bits/stdc++.h>
using namespace std;
const int mxn = (int)1e6 + 10;
string s;
int main() {
  cin >> s;
  int n = s.size();
  int i = 0, j = n - 1;
  int ret = 0;
  int open = 0;
  while (i < n) {
    if (s[i] == '(') {
      open++;
    } else {
      if (open > 0) {
        open--;
        ret += 2;
      }
    }
    i++;
  }
  cout << ret << endl;
}
