using System; using System.Collections.Generic; 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; bool rightFlag = 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 { rightFlag = true; } } if (s[i] == '(') { count++; } else { if (0 < count) { while (stack.Pop().C != '(') { } count--; } } if (leftFlag) { if (stack.Count < k) { Console.WriteLine(i + 1); return; } } if(rightFlag) { Console.WriteLine(stack.Count + 1); return; } } } } }