main :: IO () main = do [n, target] <- map (read :: String -> Int) . words <$> getLine s <- getLine if s !! (target - 1) == '(' then print $ f $ zip [target + 1 .. n] (drop target s) else print $ g $ zip [1..target] (take target s) f :: [(Int, Char)] -> Int f xs = fst $ foldl (\acc -> \(x, y) -> if (snd acc) == -1 && (x /= 0) then (x, -10000) else if (snd acc) == (-10000) then acc else if y == '(' then (x, (snd acc) + 1) else (x, (snd acc) - 1)) (0, 0) xs g :: [(Int, Char)] -> Int g ys = fst $ foldr (\(x, y) -> \(cx, dx) -> if dx == 0 && (cx /= 0) then (x, -10000) else if dx == (-10000) then (cx, dx) else if y == ')' then (x, dx + 1) else (x, dx - 1)) (0, 0) ys