#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, c = 0;
  string s;
  cin >> n >> s;
  int a = 0;
  int d[n];
  for (int i = 0; i < n; ++i) {
    if (s[i] == '(')
      ++a;
    else
      --a;
    d[i] = a;
  }
  for (int i = n - 2; i >= 0; --i) d[i] = min(d[i + 1], d[i]);
  int b = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '(') {
      if (d[i] - 2 >= 0 && a == 2) ++c;
      ++b;
    } else {
      if (d[i] + 2 >= 0 && a == -2) ++c;
      --b;
    }
    if (b < 0) break;
  }
  cout << c;
}
