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(); Stack stack = new Stack(); int count = 0; if (s[k - 1] == '(') { for (int i = k - 1; i < n; i++) { stack.Push(s[i]); if (s[i] == '(') { count++; } else { while (stack.Pop() != '(') { } count--; } if (stack.Count == 0) { Console.WriteLine(i + 1); return; } } } else { for (int i = k - 1; -1 < i; i--) { stack.Push(s[i]); if (s[i] == ')') { count++; } else { while (stack.Pop() != ')') { } count--; } if (stack.Count == 0) { Console.WriteLine(i + 1); return; } } } } } }