left :: String -> Int
left string = sub string 0 0
  where 
    sub :: String -> Int -> Int -> Int
    sub [] ans m = m
    sub (c:s) ans m = if c == '(' then sub s (ans+1) m else {-c == ')'-} sub s (ans-1) $ min m $ ans-1

right :: String -> Int
right string = sub string 0 0
  where 
    sub :: String -> Int -> Int -> Int
    sub [] ans m = m
    sub (c:s) ans m = if c == ')' then sub s (ans+1) m else {-c == '('-} sub s (ans-1) $ min m $ ans-1


main :: IO ()
main = do
  n <- readLn::IO Int
  s <- getLine
  
  putStrLn $ (replicate ((-1)*(left s)) '(') ++ s ++ (replicate ((-1)*(right $ reverse s)) ')')
      
      