#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1;
  stack<int> s;
  int i, k1 = 0, k2 = 0, kol = 0;
  cin >> s1;
  for (i = 0; i < s1.length(); ++i)
    if (s1[i] == '(')
      s.push(1);
    else
      s.push(-1);
  while (s.size() != 0) {
    if (s.top() == 1)
      if (k1 + 1 > k2)
        kol++;
      else
        k1++;
    else
      k2++;
    s.pop();
  }
  kol += k2 - k1;
  cout << s1.length() - kol << endl;
  return 0;
}
