#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long power(long long a, long long b, long long m = 1000000007) {
  long long answer = 1;
  while (b) {
    if (b & 1) answer = (answer * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return answer;
}
using namespace std;
void ctrl() { cout << "Control" << endl; }
long long make_num(string p) {
  stringstream geek(p);
  long long x = 0;
  geek >> x;
  return x;
}
string make_str(long long x) {
  ostringstream str1;
  str1 << x;
  string geek = str1.str();
  return geek;
}
const long long N = 1000000 + 5;
long long high[4 * N + 10], low[4 * N + 10];
string p;
struct Node {
  long long balance, open, close;
};
struct Node Tree[4 * N + 10];
void init(long long node, long long start, long long end) {
  high[node] = end;
  low[node] = start;
  if (start == end) {
    return;
  }
  long long mid = (start + end) / 2;
  init(2 * node, start, mid);
  init(2 * node + 1, mid + 1, end);
}
struct Node combine(struct Node a, struct Node b) {
  struct Node res;
  long long x = min(a.open, b.close);
  res.balance = a.balance + b.balance + x;
  res.close = a.close + b.close - x;
  res.open = a.open + b.open - x;
  return res;
}
void build(long long node, long long start, long long end) {
  if (low[node] == high[node]) {
    if (p[low[node]] == '(')
      Tree[node].open = 1, Tree[node].close = 0;
    else {
      Tree[node].open = 0, Tree[node].close = 1;
    }
    Tree[node].balance = 0;
    return;
  }
  long long mid = (start + end) / 2;
  build(2 * node, start, mid);
  build(2 * node + 1, mid + 1, end);
  Tree[node] = combine(Tree[2 * node], Tree[2 * node + 1]);
}
struct Node query(long long node, long long start, long long end) {
  if (low[node] > end || high[node] < start || start > end)
    return Node{0, 0, 0};
  else if (start <= low[node] && end >= high[node]) {
    return Tree[node];
  }
  struct Node x = query(2 * node, start, end);
  struct Node y = query(2 * node + 1, start, end);
  struct Node res = combine(x, y);
  return res;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  long long n;
  cin >> n;
  init(1, 0, n - 1);
  cin >> p;
  build(1, 0, n - 1);
  long long cnt = 0;
  for (long long i = 0; i < n; i++) {
    struct Node h = query(1, 0, i - 1);
    if (p[i] == ')') {
      h = combine(h, Node{0, 1, 0});
    } else {
      h = combine(h, Node{0, 0, 1});
    }
    h = combine(h, query(1, i + 1, n - 1));
    if (2 * h.balance == n) cnt++;
  }
  cout << cnt;
  return 0;
}
