#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, l, m, s1[101010], s2[101010], f[201], x, y, u, v,
    lx[4 * 1010101], rx[4 * 1010101];
map<long long, long long> q;
string s;
const int MAXN = 201010;
void push(long long x, long long lm, long long rm) {
  if (lx[lm] >= rx[rm]) {
    lx[x] = lx[lm] - rx[rm] + lx[rm];
    rx[x] = rx[lm];
  } else {
    rx[x] = rx[rm] - lx[lm] + rx[lm];
    lx[x] = lx[rm];
  }
}
void build(long long x, long long l, long long r) {
  if (l == r) {
    if (s[l - 1] == '(') {
      lx[x] = 1;
    } else {
      rx[x] = 1;
    }
    return;
  }
  long long m = (l + r) >> 1, lm = x * 2, rm = x * 2 + 1;
  build(lm, l, m);
  build(rm, m + 1, r);
  push(x, lm, rm);
}
void up(long long p, long long l, long long r, long long k) {
  if (l == r) {
    lx[p] = !lx[p];
    rx[p] = !rx[p];
    return;
  }
  long long m = (l + r) >> 1, lm = p * 2, rm = p * 2 + 1;
  if (k <= m)
    up(lm, l, m, k);
  else {
    up(rm, m + 1, r, k);
  }
  push(p, lm, rm);
}
long long ans = 0;
int main() {
  cin >> n;
  cin >> s;
  build(1, 1, n);
  for (i = 1; i <= n; i++) {
    up(1, 1, n, i);
    if (lx[1] == 0 && rx[1] == 0) {
      ans++;
    }
    up(1, 1, n, i);
  }
  cout << ans;
}
