#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int maxn = 1e6 + 100;
int d[maxn];
int mins[maxn][2];
int n;
long long ans;
string a;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> a;
  int i = 0;
  mins[0][0] = mins[n + 1][1] = 1e8;
  for (long long y = 0; y < n; y++)
    i += (a[y] == '(') - (a[y] == ')'), d[y + 1] = i;
  for (long long y = 1; y <= n; y++) mins[y][0] = min(mins[y - 1][0], d[y]);
  for (long long y = n; y; y--) mins[y][1] = min(mins[y + 1][1], d[y]);
  for (long long y = 1; y <= n; y++) {
    if (a[y - 1] == '(') {
      if (mins[y - 1][0] >= 0 && mins[y][1] - 2 >= 0 && d[n] - 2 == 0) ans++;
    }
  }
  reverse(a.begin(), a.end());
  i = 0;
  for (long long y = 0; y < n; y++)
    i += (a[y] == ')') - (a[y] == '('), d[y + 1] = i;
  for (long long y = 1; y <= n; y++) mins[y][0] = min(mins[y - 1][0], d[y]);
  for (long long y = n; y; y--) mins[y][1] = min(mins[y + 1][1], d[y]);
  for (long long y = 1; y <= n; y++) {
    if (a[y - 1] == ')') {
      if (mins[y - 1][0] >= 0 && mins[y][1] - 2 >= 0 && d[n] - 2 == 0) ans++;
    }
  }
  cout << ans;
}
