#include <bits/stdc++.h>
using namespace std;
void scan() {}
template <typename T, typename... Args>
void scan(T &a, Args &...args) {
  scanf("%lld", &a);
  scan(args...);
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
void solve() {
  ;
  long long n;
  ;
  { scan(n); };
  ;
  string str;
  cin >> str;
  bool flag = false;
  long long c = 0, ans = 0;
  for (__typeof((long long)str.size()) i =
           (0) - ((0) > ((long long)str.size()));
       i != ((long long)str.size()) - ((0) > ((long long)str.size()));
       i += 1 - 2 * ((0) > ((long long)str.size()))) {
    if (str[i] == '(')
      c++;
    else
      c--;
  }
  stack<long long> st;
  if (c == 2) {
    for (__typeof((long long)str.size()) i =
             (0) - ((0) > ((long long)str.size()));
         i != ((long long)str.size()) - ((0) > ((long long)str.size()));
         i += 1 - 2 * ((0) > ((long long)str.size())))
      if (st.empty() && str[i] == ')') {
        ;
        printf("%lld\n", 0ll);
        ;
        return;
      } else if (str[i] == ')') {
        st.pop();
        if (st.size() <= 1) ans = 0;
      } else if (!st.empty()) {
        st.push(1ll);
        ans++;
      } else {
        st.push(1ll);
      }
  } else if (c == -2) {
    reverse(str.begin(), str.end());
    for (__typeof((long long)str.size()) i =
             (0) - ((0) > ((long long)str.size()));
         i != ((long long)str.size()) - ((0) > ((long long)str.size()));
         i += 1 - 2 * ((0) > ((long long)str.size())))
      if (st.empty() && str[i] == '(') {
        ;
        printf("%lld\n", 0ll);
        ;
        return;
      } else if (str[i] == '(') {
        st.pop();
        if (st.size() <= 1) ans = 0;
      } else if (!st.empty()) {
        st.push(1ll);
        ans++;
      } else {
        st.push(1ll);
      }
  };
  printf("%lld\n", ans);
  ;
}
int main() {
  solve();
  return 0;
}
