#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
long long int Mod = 1000000007;
long long int power(long long int b, long long int e, long long int m) {
  long long int res = 1;
  while (e) {
    if (e & 1) {
      res = (res * (b % m)) % m;
      e--;
    } else {
      b = ((b % m) * (b % m)) % m;
      e = e / 2;
    }
  }
  return res;
}
long long int power(long long int b, long long int e) {
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b, e / 2);
  return power(b * b, e / 2);
}
bool isprime(long long int n) {
  if (n == 1) return 0;
  for (long long int i = 2; i < sqrt(n) + 2; i++) {
    if (n % i == 0 && (i != n)) {
      return 0;
    }
  }
  return 1;
}
void Its_time_to_go_in_loop() {
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  long long int c = 0;
  vector<long long int> dp(n + 2, 1), lp(n + 2, 1), dp1(n + 2, 0),
      lp1(n + 2, 0);
  long long int x = 1;
  for (long long int i = 1; i < n + 1; i++) {
    if (s[i - 1] == '(') {
      c++;
    } else
      c--;
    dp1[i] = c;
    if (c <= -1 && x) {
      x = 0;
      for (long long int j = i; j < n + 1; j++) {
        dp[j] = 0;
      }
    }
  }
  c = 0;
  x = 1;
  for (long long int i = n; i > 0; i--) {
    if (s[i - 1] == ')') {
      c++;
    } else
      c--;
    lp1[i] = c;
    if (c <= -1 && x) {
      x = 0;
      for (long long int j = i; j > 0; j--) {
        lp[j] = 0;
      }
    }
  }
  long long int ans = 0;
  for (long long int i = 1; i < n + 1; i++) {
    if (s[i - 1] == '(') {
      if (i == 1) continue;
      if (!dp[i - 1] || (!lp[i + 1])) continue;
      if (((dp1[i - 1] - 1 == 0) && (lp1[i + 1] == 0)) ||
          (dp1[i - 1] > 0 && lp1[i + 1] > 0 &&
           ((dp1[i - 1] - 1 - lp1[i + 1]) == 0))) {
        ans++;
      }
    } else {
      if (i == n) continue;
      if (!dp[i - 1] || (!lp[i + 1])) continue;
      if (((dp1[i - 1] == 0) && (lp1[i + 1] - 1 == 0)) ||
          (dp1[i - 1] > 0 && lp1[i + 1] > 0 &&
           ((dp1[i - 1] + 1 - lp1[i + 1]) == 0))) {
        ans++;
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int t = 1, test = 1;
  while (t--) {
    Its_time_to_go_in_loop();
  }
  return 0;
}
