#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int n;
  cin >> n;
  string s;
  cin >> s;
  s = "0" + s + "0";
  vector<int> push_back(n + 2, 0);
  vector<int> sb(n + 2, 0);
  bool pc[n + 2], sc[n + 2];
  pc[0] = pc[n + 1] = sc[n + 1] = sc[0] = 1;
  for (int i = 1; i <= (n); i++) {
    push_back[i] = push_back[i - 1] + (s[i] == '(' ? 1 : -1);
    pc[i] = pc[i - 1] && (push_back[i] >= 0);
    sb[n - i + 1] = sb[n - i + 2] + (s[n - i + 1] == ')' ? 1 : -1);
    sc[n - i + 1] = sc[n - i + 2] && (sb[n - i + 1] >= 0);
  }
  int cnt = 0;
  for (int i = 1; i <= (n); i++) {
    if (pc[i - 1] && sc[i + 1]) {
      if (s[i] == '(') {
        if ((push_back[i - 1] > 0) && ((push_back[i - 1] - 1) == sb[i + 1])) {
          cnt++;
        }
      } else {
        if ((push_back[i - 1] + 1) == sb[i + 1]) {
          cnt++;
        }
      }
    }
  }
  cout << (cnt) << '\n';
  return 0;
}
