#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
inline long long pw(long long a, long long n, long long res = 1) {
  while (n) {
    if (n & 1) res *= a;
    a *= a;
    n >>= 1;
  }
  return res;
}
inline long long read() {
  long long s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = (s << 1) + (s << 3) + ch - '0';
    ch = getchar();
  }
  return s * f;
}
const long long N = 1e5 + 20;
const long long E = 1e6 + 20;
const long long inf = 1e18;
const long long md = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long cnt1 = 0, cnt2 = 0, ans = 0;
  string s;
  cin >> s;
  for (auto i : s) {
    if (i == '(')
      cnt1++;
    else if (cnt1 > 0)
      cnt1--, ans += 2;
  }
  cout << ans;
}
