#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > v;
const int maxn = 4e6;
int vis[maxn];
int a[maxn];
const int mod = 998244353;
int n;
int s1[maxn];
int s2[maxn];
string str;
int Min1[maxn], Min2[maxn];
int Min3[maxn], Min4[maxn];
int check1(int i) {
  if (Min1[i] >= 0) return true;
  return false;
}
int len;
int check2(int i) {
  if (Min3[i] >= 2) return true;
  return false;
}
int check3(int i) {
  if (Min1[i] >= 0) return true;
  return false;
}
int check4(int i) {
  if (Min3[i] <= -2) return true;
  return false;
}
int main() {
  while (cin >> n) {
    memset(s1, 0, sizeof(s1));
    memset(s2, 0, sizeof(s2));
    memset(Min1, 0, sizeof(Min1));
    memset(Min2, 0, sizeof(Min2));
    cin >> str;
    len = str.size();
    int num1 = 0, num2 = 0;
    s1[-1] = 0;
    for (int i = 0; i < len; i++)
      if (str[i] == '(')
        s1[i] = s1[i - 1] + 1;
      else
        s1[i] = s1[i - 1] - 1;
    if (str[0] == '(')
      Min1[0] = 1;
    else
      Min1[0] = -1;
    for (int i = 1; i < len; i++) {
      Min1[i] = min(Min1[i - 1], s1[i]);
    }
    Min3[len] = 1e9;
    Min4[len] = 1e9;
    for (int i = len - 1; i >= 0; i--) {
      Min3[i] = min(Min3[i + 1], s1[i]);
    }
    for (int i = 0; i < len; i++)
      if (str[i] == '(')
        num1++;
      else
        num2++;
    if (abs(num1 - num2) != 2) {
      cout << 0 << endl;
      continue;
    }
    int ans = 0;
    for (int i = 0; i < len; i++) {
      if (str[i] == '(') {
        if (num1 - num2 == 2 && Min3[i] >= 2 && Min1[i - 1] >= 0) {
          ans++;
        }
      } else {
        if (num2 - num1 == 2 && Min3[i] >= -2 && Min1[i - 1] >= 0) {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
