#include <bits/stdc++.h>
using namespace std;
string s;
int a, b, c, d, flag, sum, ans;
int main() {
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (sum == 0) {
      flag = 0;
    }
    if (s[i] == ')' && flag == 0) continue;
    if (s[i] == '(') {
      sum++;
      flag = 1;
      ans++;
    }
    if (s[i] == ')' && flag == 1) {
      sum--;
      ans++;
    }
  }
  if (sum == 0) {
    cout << ans << endl;
    return 0;
  }
  if (sum < 0) {
    cout << ans + sum << endl;
    return 0;
  }
  if (sum > 0) {
    cout << ans - sum << endl;
    return 0;
  }
  return 0;
}
