#include #include #include using namespace std; int main() { int N, K; string S; cin >> N >> K >> S; --K; if (S[K] == '(') { int open = 0; for (int i = K; i < N; ++i) { if (S[i] == '(') { ++open; } else { --open; } if (open == 0) { cout << i + 1 << endl; break; } } } else { int close = 0; for (int i = K; i >= 0; --i) { if (S[i] == ')') { ++close; } else { --close; } if (close == 0) { cout << i + 1 << endl; break; } } } }