#include <bits/stdc++.h>
using namespace std;
int b[1000010];
int rb[1000010];
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int l = 0, r = n - 1;
  for (int i = 0; i < n; i++) {
    b[i] = (s[i] == '(') - (s[i] == ')');
    if (i > 0) {
      b[i] += b[i - 1];
    }
    if (b[i] < 0 and r == n - 1) r = i;
  }
  for (int i = n - 1; i >= 0; i--) {
    rb[i] = (s[i] == ')') - (s[i] == '(');
    if (i != n - 1) {
      rb[i] += rb[i + 1];
    }
    if (rb[i] < 0 and l == 0) l = i;
  }
  int ans = 0;
  for (int i = l; i <= r; i++) {
    if (s[i] == '(') {
      int p = b[i] - 2;
      int s = rb[i + 1];
      if (p == s and p >= 0) {
        ans++;
      }
    } else {
      int p = b[i] + 2;
      int s = rb[i + 1];
      if (p == s and p >= 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
