#include <bits/stdc++.h>
using namespace std;
bool prime[1000005];
void sieve(int n) {
  for (int i = 0; i < n; i++) prime[i] = true;
  prime[0] = false, prime[1] = false;
  for (int i = 2; i * i <= n; i++) {
    if (prime[i] == true) {
      for (int j = i * i; j <= n; j += i) prime[j] = false;
    }
  }
}
int main() {
  stack<char> s;
  string st;
  cin >> st;
  int c = 0;
  for (int i = 0; i < st.size(); i++) {
    if (st[i] == '(')
      s.push('(');
    else if (s.size())
      s.pop(), c++;
  }
  cout << c * 2 << endl;
  return 0;
}
