#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  queue<char> q;
  int ans = 0;
  for (int i = 0; i < s.length(); i++) {
    if (q.empty()) {
      if (s[i] == '(')
        q.push(s[i]), ans++;
      else
        continue;
    } else {
      if (s[i] == '(') {
        q.push(s[i]);
        ans++;
      } else if (!q.empty() and s[i] == ')') {
        q.pop();
        ans++;
      }
    }
  }
  while (!q.empty()) {
    q.pop();
    ans--;
  }
  cout << ans;
  return 0;
}
