fun main(args: Array<String>) {
    val N = nextInt()
    val S = next()
    val Q = java.util.ArrayDeque<Char>()
    var openBracket = 0
    S.forEach { s ->
        when (s) {
            '(' -> openBracket += 1
            ')' -> if (openBracket > 0) openBracket -= 1
                   else Q.addFirst('(')
        }
        Q.addLast(s)
    }
    val ans = Q.joinToString("") + ")".repeat(openBracket)
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
