#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 * 1e6 + 55;
bool vis[maxn];
int n;
string s;
struct ans {
  int left, right;
};
ans st[maxn << 2];
ans config(ans a, ans b) {
  ans c;
  c.right = a.right;
  c.left = b.left;
  int mn = min(a.left, b.right);
  c.left += a.left - mn;
  c.right += b.right - mn;
  return c;
}
void build(int i, int l, int r) {
  int m = (l + r) >> 1;
  if (l == r) {
    s[l] == '(' ? (st[i].left = 1) : (st[i].right = 1);
    return;
  }
  int lc, rc;
  lc = i << 1;
  rc = (i << 1) | 1;
  build(lc, l, m);
  build(rc, m + 1, r);
  st[i] = config(st[lc], st[rc]);
}
void update(int x, int i, int l, int r) {
  if (l == r) {
    if (s[l] == '(')
      s[l] = ')';
    else
      s[l] = '(';
    st[i].left = st[i].right = 0;
    s[l] == '(' ? st[i].left = 1 : st[i].right = 1;
    return;
  }
  int m = (l + r) >> 1;
  int lc = i << 1, rc = (i << 1) | 1;
  if (x <= m)
    update(x, lc, l, m);
  else
    update(x, rc, m + 1, r);
  st[i] = config(st[lc], st[rc]);
}
ans query(int ql, int qr, int i, int l, int r) {
  if (ql <= l && qr >= r) return st[i];
  if (ql > r || qr < l) return ans();
  int m = (l + r) >> 1;
  int lc = i << 1, rc = (i << 1) | 1;
  return config(query(ql, qr, lc, l, m), query(ql, qr, rc, m + 1, r));
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  memset(vis, false, sizeof vis);
  cin >> n >> s;
  build(1, 0, n - 1);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    update(i, 1, 0, n - 1);
    ans += (st[1].left == 0 && st[1].right == 0);
    update(i, 1, 0, n - 1);
  }
  cout << ans;
}
