#include <bits/stdc++.h>
using namespace std;
int n, cntl, cntr;
char s[1000005];
int main() {
  cin >> n >> (s + 1);
  for (int i = 1; i <= n; i++) {
    if (s[i] == ')')
      cntr++;
    else
      cntl++;
    if (cntr - cntl > 2 || n % 2) {
      puts("0");
      return 0;
    }
  }
  if (abs(cntl - cntr) != 2) {
    puts("0");
    return 0;
  }
  int ans = 0, l = 0, r = 0;
  if (cntl > cntr) {
    int tl = 0, tr = 0;
    for (int i = 1; i <= n; i++) {
      if (s[i] == ')')
        tr++;
      else
        tl++;
      if (tr > tl) {
        puts("0");
        return 0;
      }
    }
    for (int i = n; i >= 1; i--) {
      if (s[i] == '(')
        l++;
      else
        r++;
      if (l - r > 0) {
        ans = l;
        break;
      }
    }
  } else {
    for (int i = 1; i <= n; i++) {
      if (s[i] == '(')
        l++;
      else
        r++;
      if (r - l > 0) {
        ans = r;
        break;
      }
    }
  }
  cout << ans << endl;
}
