#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e2 + 7, MOD = 1e9 + 7, inf = 1e9, N = 3e5 + 7;
int n, k, cont, ans, a;
string d;
int main() {
  cin >> d;
  for (int i = 0; i < d.size(); i++) {
    if (d[i] == '(') a++;
    if (d[i] == ')' && a) a--, ans += 2;
  }
  return cout << ans << "\n", 0;
}
