#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433;
const long long M = 998244353;
long long n, t, a[1000100], k;
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> s;
  if (n % 2) return cout << 0, 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == '(')
      t++;
    else
      t--;
    a[i] = t;
  }
  if (t == 2) {
    for (long long i = 0; i < n; i++) {
      if (a[i] < 0) return cout << 0, 0;
      if (a[i] >= 2) {
        if (s[i] == '(') k++;
      } else
        k = 0;
    }
  }
  if (t == -2) {
    for (long long i = n - 1; i >= 0; i--) {
      if (a[i] < -2) return cout << 0, 0;
      if (a[i] < 0) k = 0;
      if (a[i] > -2)
        if (s[i] == ')') k++;
    }
  }
  cout << k;
}
