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