#include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long int; #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define YES(n) std::cout << ((n) ? "YES" : "NO" ) << "\n"; #define Yes(n) std::cout << ((n) ? "Yes" : "No" ) << "\n"; #define ALL_INCLUDED_ENVIRONMENT template class C> std::ostream& operator<<(std::ostream& o, const C& v) { o << "{"; bool init = 1; for (auto e : v) { if (init) { init = 0; } else { o << ", "; } o << e; } o << "}"; return o; } ll n, k, ans; string s; stack stk; int main() { // cin.tie(0); // ios::sync_with_stdio(false); cin >> n >> k; cin.ignore(); getline(cin, s); k--; if (s[k] == ')') { REP (i, n) { if (i == k) { ans = stk.top()+1; break; } if (s[i] == '(') { stk.push(i); } else { stk.pop(); } } } else { REP (i, n) { if (s[i] == '(') { stk.push(i); } else { if (stk.top() == k) { ans = i+1; break; } stk.pop(); } } } cout << ans << "\n"; return 0; }