#include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int N, K, ans; string S; cin >> N >> K >> S; /* stack> q; set> st; for (int i = 0; i < S.size(); i++) { if (S[i] == '(') { q.push(pair(i+1, -1)); } else { q.top().second = i + 1; st.insert(q.top()); q.pop(); } } set>::iterator it = st.begin(); while (it != st.end()) { if (S[K - 1] == '(' && (*it).first == K) { ans = (*it).second; break; } else if(S[K - 1] == ')' && (*it).second == K){ ans = (*it).first; break; } it++; } */ int d = 0, i; if (S[K-1] == '(') { for (i = K - 1; ;i++) { if (S[i] == '(') d++; else d--; if (d == 0) break; } } else { for (i = K - 1; ; i--) { if (S[i] == ')') d++; else d--; if (d == 0) break; } } cout << i+1 << endl; return 0; }