#include <bits/stdc++.h>
const long long MAX = 1e6 + 5;
const long long MOD = 1e9 + 7;
using namespace std;
int sum[MAX], minn[MAX];
int main() {
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n;
  cin >> s;
  sum[0] = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(')
      sum[i + 1] = sum[i] + 1;
    else if (s[i] == ')')
      sum[i + 1] = sum[i] - 1;
  }
  minn[n] = sum[n];
  for (int i = n - 1; i >= 0; i--) minn[i] = min(minn[i + 1], sum[i]);
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (sum[i] < 0) break;
    int t = sum[i];
    if (s[i] == ')')
      t++;
    else if (s[i] == '(')
      t--;
    if (t < 0) continue;
    if (sum[n] - sum[i + 1] + t != 0) continue;
    if (minn[i + 1] - sum[i + 1] + t < 0) continue;
    res++;
  }
  cout << res << '\n';
  return 0;
}
