#include <bits/stdc++.h>
using namespace std;
int main() {
  long int i, pos;
  vector<int> in, out;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '(')
      in.push_back(i);
    else
      out.push_back(i);
  }
  long long int count = 0;
  pos = -1;
  for (i = 0; i < in.size(); i++) {
    pos = lower_bound(out.begin() + pos + 1, out.end(), in[i]) - out.begin();
    if (pos >= out.size())
      break;
    else {
      ++count;
    }
  }
  cout << 2 * count << "\n";
  return 0;
}
