#include using namespace std; int main() { int n, k; cin >> n >> k; string s; cin >> s; char start; int proceed = 0; int status = 1; if (s[k - 1] == '(') { proceed = 1; } else { proceed = -1; } start = s[k - 1]; while (true) { k += proceed; if (s[k - 1] == start) { status++; } else { status--; } if (!status) { cout << k << endl; // system("pause"); return 0; } } }