#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vb = vector<bool>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  int open = 0, close = 0;
  int n = s.length();
  for (int i = 0; i < (int)n; i++) {
    if (s[i] == '(') {
      open++;
    } else if (close < open) {
      close++;
    }
  }
  cout << close * 2 << endl;
}
