import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable long mod = 10^^9 + 7;

void main(){
    auto n = readln.chomp.to!int;
    auto s = readln.chomp;

    int stack;
    int lb, rb;

    foreach(ch ; s){
        if (ch == '('){
            stack += 1;
        }
        else {
            if (stack == 0){
                lb += 1;
            } 
            else {
                stack--;
            }
        }
    }

    rb = stack;

    auto ans = repeat("(", lb).join ~ s ~ repeat(")", rb).join;

    writeln(ans);
}


void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        throw new Exception("args num < input num");
    }
}