#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
  string s;
  cin >> s;
  stack<char> stk;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '(')
      stk.push('(');
    else if (s[i] == ')' && !stk.empty())
      stk.pop();
    else if (stk.empty())
      ans++;
  }
  ans += stk.size();
  printf("%d", s.size() - ans);
  return 0;
}
