#include <bits/stdc++.h>
using namespace std;
stack<char> q;
int main() {
  ios::sync_with_stdio(0);
  string s;
  cin >> s;
  long long sum = 0;
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == ')') {
      q.push(s[i]);
    } else if (s[i] == '(' && q.size() != 0) {
      q.pop();
      sum += 2;
    }
  }
  cout << sum;
}
