#include int main() { int N; char S[200001]; scanf("%d", &N); scanf("%s", S); int i, k, ans = 0; for (i = 0, k = 1; i < N; i++) { if (k == 0) { if (S[i] == '(') k = 2; else if (S[i] == '?') { if (S[i+1] == '?' || S[i+1] == ')') k = 2; } } else { if (S[i] == '(') k++; else { k--; if (k == 0) ans++; } } } if (k == 1) ans++; printf("%d\n", ans); fflush(stdout); return 0; }