#include <bits/stdc++.h>
using namespace std;
vector<int> numbers, temp;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  for (long long i = 0; i < n; ++i) {
    if (s[i] == '(')
      numbers.push_back(1);
    else
      numbers.push_back(-1);
    temp.push_back(0);
  }
  int cnt = 0;
  if (numbers[0] == 1) temp[0] = 1;
  for (long long i = 1; i < n; ++i) {
    if (numbers[i] == 1) {
      temp[i] = temp[i - 1] + 1;
    }
    if (numbers[i] == -1) {
      if (temp[i - 1] >= 1) {
        ++cnt;
        temp[i] = temp[i - 1] - 1;
      }
    }
  }
  cout << cnt * 2;
  return 0;
}
