solve :: String -> (Int, Int) -> (Int, Int)
solve [] lr = lr
solve (s:ss) (l, r) = solve ss (nextl, nextr)
    where d = if s == '(' then 1 else -1
          nextl = if d /= 1 && r == 0 then l + 1 else l
          nextr = max 0 (r + d)

main :: IO ()
main = do
  getLine
  s <- getLine
  let (l, r) = solve s (0, 0)
  putStrLn $ replicate l '(' ++ s ++ replicate r ')'