#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
int fx[] = {-1, 1, 0, 0, -1, -1, 1, 1};
int fy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int TLx[] = {0, -1, -1, 0};
int TLy[] = {-1, -1, 0, 0};
int TRx[] = {-1, -1, 0, 0};
int TRy[] = {0, 1, 1, 0};
int BLx[] = {0, 1, 1, 0};
int BLy[] = {-1, -1, 0, 0};
int BRx[] = {0, 1, 1, 0};
int BRy[] = {1, 1, 0, 0};
stack<char> st;
int main() {
  string s;
  cin >> s;
  int x = s.size(), cnt = 0;
  for (int i = 0; i < x; i++) {
    if (s[i] == '(')
      st.push(s[i]);
    else if (s[i] == ')' && !st.empty() && st.top() == '(')
      st.pop(), cnt += 2;
  }
  cout << cnt << endl;
  return 0;
}
