fun main(args: Array<String>) {
    abc064d()
}

fun abc064d() {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val answer = StringBuilder(s)
    var unpairedLeft = 0
    s.map { it == '(' }.forEach { isLeft ->
        if (isLeft) {
            unpairedLeft++
        } else {
            if (unpairedLeft > 0) {
                unpairedLeft--
            } else {
                answer.insert(0, '(')
            }
        }
    }

    answer.append(")".repeat(unpairedLeft))

    println(answer)
}
