#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, c, k, mx;
  string str;
  cin >> str;
  i = 0;
  k = str.size() - 1;
  c = 0;
  mx = 0;
  while (i <= k) {
    if (str[i] == '(')
      c++;
    else {
      if (c > 0) {
        mx++;
        c--;
      }
    }
    i++;
  }
  cout << mx * 2 << endl;
  return 0;
}
