#include <bits/stdc++.h>
using namespace std;
int main() {
  int count = 0;
  string brack;
  cin >> brack;
  stack<char> extra;
  int x = brack.length();
  for (int i = 0; i < x; i++) {
    if (brack[i] == '(')
      extra.push(brack[i]);
    else if (extra.size() > 0)
      extra.pop();
    else
      count++;
  }
  cout << x - extra.size() - count << endl;
  return 0;
}
