fun main(args: Array<String>) {
    readLine()
    val S = readLine()!!
    var open = 0
    val sb = StringBuilder()
    for (i in 0..S.length - 1) {
        when(S[i]) {
            '(' -> {
                open++
            }
            ')' -> {
                if (open > 0) {
                    open--
                } else {
                    sb.insert(0, '(')
                }
            }
        }
        sb.append(S[i])
    }
    while (open > 0) {
        open--
        sb.append(')')
    }
    println(sb)
}