#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int cnt[maxn], n, x = 0;
string s;
int main() {
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    x += s[i] == '(';
    x -= s[i] == ')';
    cnt[i] = x;
  }
  for (int i = n - 2; i >= 0; --i) cnt[i] = min(cnt[i + 1], cnt[i]);
  int ans = 0, b = 0;
  for (int i = 0; i < n; ++i) {
    b += s[i] == '(';
    b -= s[i] == ')';
    if (s[i] == '(') {
      if (cnt[i] >= 2 && x == 2) ans++;
    } else {
      if (cnt[i] >= -2 && x == -2) ans++;
    }
    if (b < 0) break;
  }
  cout << ans << endl;
  return 0;
}
