#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
const int N = 1e6+10020;
char S[N];
int Sum[N],Minn[N];
signed main()
{
#ifdef TSUKIAKIOI
freopen("data.in","r",stdin);
#endif
int n;scanf("%d",&n);
scanf("%s",S);
int len = n;
for(int i=1;i<=len;++i)
Sum[i] = (S[i-1] == ')' ? -1 : 1) + Sum[i-1];
int tot = 0;
Minn[len+1]=1e9;
for(int i=len;i;--i)
Minn[i] = min(Minn[i+1],Sum[i]),
tot += S[i-1] == ')' ? 1 : -1;
if(tot != 2 && tot != -2)
return puts("0"),0;
int ans = 0;
int minn = 0;
for(int i=1;i<=n;++i){
if(tot == 2 && S[i-1] == '(') goto end;
if(tot == -2 && S[i-1] == ')') goto end;
if(minn < 0)
break;
if(Minn[i] >= -tot){
#ifdef HJWWWW
printf("%d\n",i);
#endif
ans++;
}
end:
minn = min(minn,Sum[i]);
}
printf("%d\n",ans);
return 0;
}