let () = let n, k = Scanf.scanf "%d %d " (fun n k -> n, k) in let s = Scanf.scanf "%s " (fun i -> i) in let a = Array.make (n + 1) 0 in String.iteri (fun i c -> if c = '(' then a.(i) <- a.(i) + 1 else a.(i+1) <- a.(i+1) - 1) s; Array.iteri (fun i e -> if i > 0 then a.(i) <- a.(i) + a.(i-1)) a; let k = k - 1 in if s.[k] = '(' then let rec doit i = if i = n then assert false else if a.(i) = a.(k) then i + 1 else doit (i + 1) in doit (k + 1) |> Printf.printf "%d\n" else let rec doit i = if i < 0 then assert false else if a.(i) = a.(k) then i + 1 else doit (i - 1) in doit (k - 1) |> Printf.printf "%d\n"