const lines = require('fs') .readFileSync('/dev/stdin', 'utf-8') .trim().split('\n').values(); const [N, K] = lines.next().value.split(' ').map(x => Number(x)); const S = lines.next().value; const bracket = []; const position = []; let ans; bracket.push(S[0]); position.push(0); for (let i = 1; i < N; i++) { if (S[i] === ')' && bracket[bracket.length - 1] === '(') { bracket.pop(); let p = position.pop(); if (p === K - 1) { ans = i + 1; break; } if (i === K - 1) { ans = p + 1; break; } } else { bracket.push(S[i]); position.push(i); } } console.log(ans);