#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int depth = 0;
  for (int i = 0; i < n; i++) {
    depth += (s[i] == '(' ? 1 : -1);
  }
  if (depth != 2 && depth != -2) {
    cout << "0\n";
    return 0;
  }
  if (depth == 2) {
    depth = 0;
    int ans = 0;
    bool can = true;
    for (int i = 0; i < n; i++) {
      if (s[i] == '(') {
        if (depth - 1 >= 0) {
          ans++;
        }
      }
      depth += (s[i] == '(' ? 1 : -1);
      if (depth <= 1) {
        ans = 0;
      }
      if (depth < 0) {
        can = false;
      }
    }
    if (!can) {
      cout << "0\n";
      return 0;
    }
    cout << ans << '\n';
  } else if (depth == -2) {
    depth = 0;
    int ans = 0;
    bool can = true;
    for (int i = 0; i < n; i++) {
      if (s[i] == ')') {
        ans++;
      }
      depth += (s[i] == '(' ? 1 : -1);
      if (depth < 0) {
        break;
      }
    }
    depth = 0;
    for (int i = 0; i < n; i++) {
      depth += (s[i] == '(' ? 1 : -1);
      if (depth < -2) {
        can = false;
      }
    }
    if (!can) {
      cout << "0\n";
      return 0;
    }
    cout << ans << '\n';
  }
  return 0;
}
