import Data.List
import Data.Ord

main = do
  n <- readLn :: IO Int
  s <- getLine
  
  putStrLn $ minimumBy (comparing length) $ filter isParenCorrect [open ++ s ++ close | close <- (take (n+1) $ iterate (')':) []), open <- (take (n+1) $ iterate ('(':) [])]

  where
    isParenCorrect xs = last b == 0 && find (<0) b == Nothing
      where
        a = map f xs
        b = scanl (+) 0 a
        f '(' = 1
        f ')' = -1
