#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 7;
int a[N], suff[N];
int main() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    a[i] = a[i - 1] + (s[i - 1] == '(') - (s[i - 1] == ')');
  }
  int cnt = 0;
  suff[n] = a[n];
  for (int i = n - 1; i >= 1; i--) {
    suff[i] = min(a[i], suff[i + 1]);
  }
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == '(') {
      if (a[n] == +2 && suff[i] - 2 >= 0) ++cnt;
    } else {
      if (a[n] == -2 && suff[i] + 2 >= 0) ++cnt;
    }
    if (a[i] < 0) break;
  }
  cout << cnt << endl;
}
