#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  string seq;
  cin >> seq;
  int lcnt = 0;
  int ans = 0;
  for (int i = 0; i < seq.size(); ++i) {
    if (seq[i] == '(')
      ++lcnt;
    else {
      if (lcnt == 0) continue;
      --lcnt, ++ans;
    }
  }
  cout << ans * 2 << endl;
  return 0;
}
