#include <bits/stdc++.h>
using namespace std;
int main() {
  int left = 0;
  int right = 0;
  int count = 0;
  string s;
  cin >> s;
  int n = s.length();
  for (int i = 0; i < n; i++) {
    if (s[i] == '(')
      left++;
    else
      right++;
    if (right > left) {
      count++;
      right--;
    }
  }
  count += left - right;
  cout << n - count << endl;
  return 0;
}
