#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> neighbor(100000 + 9), emptyNeighbor(100000 + 9);
bool visited[11];
int dfs(int node) {
  visited[node] = true;
  for (int neighbor : neighbor[node])
    if (!visited[neighbor]) {
      dfs(neighbor);
    }
}
int val = 0;
bool prime(int num) {
  bool check = false;
  for (int i = 2; i < num; i++) {
    if (num % i == 0) {
      check = true;
      break;
    }
  }
  return check;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  stack<char> st;
  int ans = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '(')
      st.push('(');
    else {
      if (!st.empty()) {
        ans += 2;
        st.pop();
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
