#include <bits/stdc++.h>
using namespace std;
int main() {
  int size;
  string str;
  cin >> size >> str;
  vector<int> pref(size), suf(size);
  int begIndex = 0, endIndex = size - 1;
  for (int i = 0; i < size; i++) {
    pref[i] = (str[i] == '(' ? 1 : -1) + (i == 0 ? 0 : pref[i - 1]);
    if (pref[i] < 0) endIndex = min(i, endIndex);
  }
  for (int i = size - 1; i >= 0; i--) {
    suf[i] = (str[i] == '(' ? 1 : -1) + (i == size - 1 ? 0 : suf[i + 1]);
    if (suf[i] > 0) begIndex = max(i, begIndex);
  }
  int ans = 0;
  for (int i = begIndex; i <= endIndex; i++) {
    int evalLeft = (i == 0 ? 0 : pref[i - 1]),
        evalRight = (i == size - 1 ? 0 : suf[i + 1]);
    if ((evalLeft + evalRight == -1 && str[i] == ')') ||
        (evalLeft + evalRight == 1 && str[i] == '('))
      ans++;
  }
  cout << ans << endl;
  return 0;
}
