#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string s;
  cin >> s;
  long long n = s.length();
  long long ans = 0;
  long long open = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == '(')
      open++;
    else {
      if (open > 0) {
        open--;
      } else
        ans++;
    }
  }
  cout << n - ans - open;
  return 0;
}
