import Data.List

main = do
 getLine
 as <- getLine
 putStrLn (ins as)

ins as
 | valid as == (Just 0) = as
 | otherwise = replicate nbr '(' ++ as ++ replicate nbl ')'
  where
   nbr = let (br,bl) = partition (==')') $ reverse $ dropWhile (=='(') $ reverse as
          in length br - length bl
   nbl = let (bl,br) = partition (=='(') $ dropWhile (==')') as
          in length bl - length br

valid = foldr (\b acc -> if b==')' then succ <$> acc else if b=='(' && ((Just 0) < acc) then pred <$> acc else Nothing) (Just 0)