using System; using System.Linq; using System.Collections.Generic; class Program { /// <summary> /// プログラムのエントリポイント /// </summary> /// <param name="args"></param> static void Main(string[] args) { // 括弧の数と調査する括弧のインデックスを取得する var n = (from tmp in Console.ReadLine().Split(' ') select int.Parse(tmp)).ToArray(); // 一行分読み込む var s = Console.ReadLine(); // 開きと閉じの対応をリスト化する var list = new List<Interaction>(); for (int si = 0; si < s.Length; si++) { if (s[si] == '(') { list.Add(new Interaction() { OpenIndex = si }); } else { for (int i = list.Count - 1; i >= 0; i--) { if (list[i].CloseIndex < 0) { list[i].CloseIndex = si; break; } } } } // 結果出力 if (s[n[1] - 1] == '(') Console.WriteLine(list.Where((intr) => intr.OpenIndex == n[1] - 1).ToArray()[0].CloseIndex + 1); else Console.WriteLine(list.Where((intr) => intr.CloseIndex == n[1] - 1).ToArray()[0].OpenIndex + 1); } /// <summary> /// 対応情報クラス /// </summary> public class Interaction { /// <summary> /// 開き括弧のインデックス /// </summary> public int OpenIndex { get; set; } /// <summary> /// 閉じ括弧のインデックス /// </summary> public int CloseIndex { get; set; } = -1; } }