#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T& a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T& a, T b) {
  return a < b ? (a = b, true) : false;
}
const int INF = 1e9;
void impossible() {
  cout << 0 << '\n';
  exit(0);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  if (n % 2) impossible();
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    cnt += (s[i] == '(' ? 1 : -1);
  }
  if (abs(cnt) != 2) impossible();
  char positive;
  if (cnt == 2)
    positive = '(';
  else
    positive = ')';
  vector<int> pref(n);
  for (int i = 0; i < n; ++i) {
    pref[i] = (s[i] == '(' ? 1 : -1) + (i ? pref[i - 1] : 0);
  }
  vector<int> tree(n + n);
  for (int i = 0; i < n; ++i) tree[i + n] = pref[i];
  for (int i = n - 1; i > 0; --i) tree[i] = min(tree[i << 1], tree[i << 1 | 1]);
  auto query = [&](int l, int r) {
    int res = INF;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) uin(res, tree[l++]);
      if (r & 1) uin(res, tree[--r]);
    }
    return res;
  };
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (positive == '(') {
      if (s[i] == positive && pref[i] >= 2 && query(0, i) >= 0 &&
          query(i + 1, n) >= 2)
        ++ans;
    } else if (positive == ')') {
      if (s[i] == positive && query(0, i) >= 0 && query(i + 1, n) >= -2) ++ans;
    }
  }
  cout << ans << '\n';
}
