#include <bits/stdc++.h>
using namespace std;
int main() {
  string e;
  cin >> e;
  int c = 0, wrong = 0;
  for (int i = 0; i < e.size(); ++i) {
    if (e[i] == '(')
      ++c;
    else if (c > 0)
      --c;
    else
      ++wrong;
  }
  int remove = wrong + c;
  if (c < 0) c = -c;
  int res = e.size() - remove;
  if (res < 0) res = -res;
  cout << res;
  return 0;
}
