#include <bits/stdc++.h>
using namespace std;
int ok[1000001];
int main() {
  stack<pair<int, char> > S;
  int cnt = 0;
  char c;
  int i = 0;
  while (cin >> c) {
    if (S.size() == 0 || c == '(') {
      S.push(make_pair(i, c));
    } else if (S.size() != 0 && S.top().second == '(' && c == ')') {
      ok[S.top().first] = ok[i] = true;
      S.pop();
    }
    i++;
  }
  int len = 0, ans = 0, ans2 = 0;
  for (int i = 0; i < 1000001; i++) {
    if (ok[i]) {
      len++;
    } else {
      ans += len;
      len = 0;
    }
  }
  for (int i = 0; i < 1000001; i++) {
    if (ok[i]) {
      len++;
    } else {
      if (ans == len) ans2++;
      len = 0;
    }
  }
  cout << ans << endl;
}
