using System; using System.Collections.Generic; using System.Linq; namespace No22_ParenthesesCorrespondence { internal class Program { static void Main(string[] args) { string[] param = Console.ReadLine().Split(' '); int n = int.Parse(param[0]); int k = int.Parse(param[1]); string s = Console.ReadLine(); bool leftFlag = false; int count = 0; Stack<(char C, int I)> stack = new Stack<(char, int)> (); for(int i = 0; i < n; i++) { stack.Push((s[i], i)); if (i == k - 1) { if (s[i] == '(') { leftFlag = true; } else { while (true) { var pop = stack.Pop(); if (pop.C == '(') { Console.WriteLine(pop.I + 1); return; } } } } if (s[i] == '(') { count++; } else { if (0 < count) { while (stack.Pop().C != '(') { } count--; } } if (leftFlag) { if (stack.Count == 0 || stack.First().I < k - 1) { Console.WriteLine(i + 1); return; } } } } } }