#include #include int main(void) { int N = 0; int K = 0; char S[10001]; int brack[10001] = {0}; int up = 0; int down = 0; scanf("%d", &N); scanf("%d", &K); scanf("%s", S); for (int i = 0; i < N; i++) { if (S[i] == '(') { up++; brack[i] = up - down; } else { brack[i] = down - up; down++; } } if (S[K-1] == '(') { for (int i = N-1; i >= 0; i--) { if (-(brack[i]) == brack[K-1]) { printf("%d\n", i+1); break; } } } else if (S[K-1] == ')') { for (int i = 0; i < N; i++) { if (-(brack[i]) == brack[K-1]) { printf("%d\n", i+1); break; } } } return EXIT_SUCCESS; }