#include #define REP(i, a, b) for (int i = a; i < b; i++) #define REP2(i, a, b) for (int i = a; i <= b; i++) using namespace std; int main () { int N, K; cin >> N >> K; char str[10000+1]; REP2 (i, 1, N) cin >> str[i]; int cnt = 0; int n = K; for (;;) { if (str[n] == '(') { cnt++; } else { // K番目の括弧が')'の時 cnt--; } if (cnt == 0) { cout << n << endl; return 0; } if (n == N) n = 1; } return 0; }