#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.length(), t = 0, k = 0, m = 0;
  for (int i = 0; i < n; i++)
    if (s[i] == '(')
      k++;
    else {
      if (k) {
        k--;
        t += 2;
      } else {
        m += t;
        t = 0;
        k = 0;
      }
    }
  cout << m + t;
  return 0;
}
