let input = require('fs').readFileSync('/dev/stdin', 'utf8'); console.log(input); let [N, K, S] = input.split(/\s/); K = Number(K); S = S.replace(/\s/, ''); for (let i in S) { i = Number(i); if (S.match(/\([\s]*\)/)) { let M = S.match(/\([\s]*\)/); if (M.index == K - 1) { console.log(M.index + M[0].length); break; } else if (M.index + M[0].length == K - 1) { console.log(M.index); break; } S = S.replace(/\([\s]*\)/, Array(M[0].length).fill(' ').join ``); } }