#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5, mod = 1e9 + 7, inf = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  long long t = 0, cnt = 0;
  for (long long i = 0; i < s.length(); i++) {
    if (t == 0 && s[i] == ')') {
      continue;
    }
    t += (s[i] == '(' ? 1 : -1);
    if (s[i] == ')') cnt++;
  }
  cout << 2 * cnt;
}
