import Data.List

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

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

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