#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
string str;
char a[N];
pair<int, int> seg[4 * N];
pair<int, int> mrg(pair<int, int> n1, pair<int, int> n2) {
  pair<int, int> ans;
  int mn = min(n1.first, n2.second);
  n1.first -= mn;
  n2.second -= mn;
  ans = {n1.first + n2.first, n1.second + n2.second};
  return ans;
}
void build(int nd, int L, int R) {
  if (L == R) {
    if (a[L] == ')')
      seg[nd].second += 1;
    else
      seg[nd].first += 1;
    return;
  }
  int mid = (L + R) >> 1;
  build((2 * nd), L, mid);
  build((2 * nd) + 1, mid + 1, R);
  seg[nd] = mrg(seg[(2 * nd)], seg[(2 * nd) + 1]);
}
int main() {
  cin >> str;
  int len = str.length();
  for (int i = 1; i <= len; i++) a[i] = str[i - 1];
  build(1, 1, len);
  cout << len - (seg[1].first + seg[1].second) << endl;
  return 0;
}
