#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  long long n = a.size(), s1 = 0, s2 = 0, c = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == '(')
      s1++;
    else
      s2++;
    if (s2 > s1) s2 = 0;
    if (s1 >= s2 && s2 > 0) {
      c += 2;
      s1--;
      s2--;
    }
  }
  cout << c;
  return 0;
}
