#include <stdio.h>
#include <string.h>
#include <stdlib.h> 
#define MAX_SIZE 100000 
int main() {
    int n;
    scanf("%d", &n); 

    char glyph_string[MAX_SIZE + 1]; 
    scanf("%s", glyph_string); 
    if (strlen(glyph_string) != n) {
        printf("Invalid input\n");
        return 0;
    }

    for (int i = 0; i < n; i++) {
        if (glyph_string[i] != '(' && glyph_string[i] != ')') {
            printf("Invalid input\n");
            return 0;
        }
    }

    int stack[MAX_SIZE];
    int top = -1; 
    int maxLength = 0;
    stack[++top] = -1; 

    for (int i = 0; i < n; i++) {
        if (glyph_string[i] == '(') {
            stack[++top] = i; 
        } else { 
            if (top != -1) { 
                top--; 
                    int currentLength = i - stack[top];
                    if (currentLength > maxLength) {
                        maxLength = currentLength; 
                    }
                } else {
                    stack[++top] = i; 
                }
            } else {
                stack[++top] = i;
            }
        }
    }

    printf("%d\n", maxLength); 

    return 0;
}