#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
  return (b) == 0 ? (a) : gcd((b), ((a) % (b)));
}
template <class T>
inline T lcm(T a, T b) {
  return ((a) / gcd((a), (b)) * (b));
}
template <class T>
inline T BigMod(T Base, T power, T M = 1000000007) {
  if (power == 0) return 1;
  if (power & 1)
    return ((Base % M) * (BigMod(Base, power - 1, M) % M)) % M;
  else {
    T y = BigMod(Base, power / 2, M) % M;
    return (y * y) % M;
  }
}
template <class T>
inline T ModInv(T A, T M = 1000000007) {
  return BigMod(A, M - 2, M);
}
int fx[] = {-1, +0, +1, +0, +1, +1, -1, -1, +0};
int fy[] = {+0, -1, +0, +1, +1, -1, +1, -1, +0};
int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n;
string s;
int open[2000050], close[2000050];
int tree[4 * 2000050];
void Build(int node, int b, int e) {
  if (b == e) {
    tree[node] = open[b] - close[b];
    return;
  }
  int mid = (b + e) >> 1;
  int left = 2 * node;
  int right = left + 1;
  Build(left, b, mid);
  Build(right, mid + 1, e);
  tree[node] = min(tree[left], tree[right]);
}
int query(int node, int b, int e, int l, int r) {
  if (b > r || l > e) return INT_MAX / 10;
  if (b >= l && e <= r) return tree[node];
  int mid = (b + e) >> 1;
  int left = 2 * node;
  int right = left + 1;
  int p1 = query(left, b, mid, l, r);
  int p2 = query(right, mid + 1, e, l, r);
  return min(p1, p2);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == '(')
      open[i]++;
    else
      close[i]++;
    open[i] += open[i - 1];
    close[i] += close[i - 1];
  }
  Build(1, 1, n);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == '(') {
      int x = query(1, 1, n, 1, i - 1);
      int y = query(1, 1, n, i, n);
      if (x >= 0 && y >= 2 && open[n] - close[n] == 2) ans++;
    } else {
      int x = query(1, 1, n, 1, i - 1);
      int y = query(1, 1, n, i, n);
      if (x >= 0 && y >= -2 && open[n] - close[n] == -2) ans++;
    }
  }
  cout << ans;
  return 0;
}
