#include <bits/stdc++.h>
#pragma GCC optimization("O3")
using namespace std;
const long long inf = 1e9;
const long long inf2 = 1e18;
const long long MAX = 1e5 + 5;
const long long MOD = 1e9 + 7;
const double pi = acos(-1.0);
const double EPS = 1e-9;
void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
}
long long n, temp, t;
string s;
int main() {
  init();
  cin >> s;
  n = s.length();
  for (long long i = 0; i <= n - 1; i++) {
    if (s[i] == '(')
      temp++;
    else {
      if (temp > 0) {
        t += 2;
        temp--;
      }
    }
  }
  cout << t << '\n';
}
