#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  string s;
  cin >> n;
  cin >> s;
  vector<int> arr(n);
  int a = 0;
  int absmin = 1e9 + 7;
  int indmin = -1;
  for (int i = 0; i < n; i++) {
    if (s[i] == ')')
      a--;
    else
      a++;
    arr[i] = a;
    if (absmin > a && a < 0) {
      absmin = a;
      if (indmin == -1) indmin = i;
    }
  }
  int min = 0;
  int max = 1e9 + 7;
  int sum = 0;
  if (absmin >= -2) {
    for (int i = n - 1; i >= 0; i--) {
      if (arr[i] < min) min = arr[i];
      if (arr[i] < max && arr[i] >= 0) max = arr[i];
      if (absmin >= 0 || i <= indmin) {
        if (arr[n - 1] == -2 && s[i] == ')') sum++;
        if (max >= 2 && arr[n - 1] == 2 && s[i] == '(') sum++;
      }
    }
  }
  cout << sum;
}
