import sys



sys.setrecursionlimit(10 ** 7)

f_inf = float('inf')

mod = 10 ** 9 + 7





def resolve():

    n = int(eval(input()))

    S = eval(input())



    insert_L = 0

    cnt_L = 0



    for s in S:

        if s == '(':

            cnt_L += 1

        else:

            if cnt_L:

                cnt_L -= 1

            else:

                insert_L += 1



    insert_R = cnt_L



    res = '(' * insert_L + S + ')' * insert_R

    print(res)





if __name__ == '__main__':

    resolve()

import sys



sys.setrecursionlimit(10 ** 7)

f_inf = float('inf')

mod = 10 ** 9 + 7





def resolve():

    n = int(eval(input()))

    S = eval(input())



    right = 0

    left = 0

    for i in range(n):

        if S[i] == "(":

            left += 1

        else:

            if left:

                left -= 1

            else:

                right += 1

    res = "(" * right + S + ")" * left

    print(res)





if __name__ == '__main__':

    resolve()

import sys

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    n = int(eval(input()))
    S = eval(input())
    insert_L = 0
    cnt_L = 0
    for s in S:
        if s == "(":
            cnt_L += 1
        else:
            if cnt_L:
                cnt_L -= 1
            else:
                insert_L += 1
    insert_R = cnt_L
    res = "(" * insert_L + S + ")" * insert_R
    print(res)


if __name__ == "__main__":
    resolve()

import sys

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    n = int(eval(input()))
    S = eval(input())
    right = 0
    left = 0
    for i in range(n):
        if S[i] == "(":
            left += 1
        else:
            if left:
                left -= 1
            else:
                right += 1
    res = "(" * right + S + ")" * left
    print(res)


if __name__ == "__main__":
    resolve()

-    insert_L = 0 -    cnt_L = 0 -    for s in S: -        if s == "(": -            cnt_L += 1 +    right = 0 +    left = 0 +    for i in range(n): +        if S[i] == "(": +            left += 1 -            if cnt_L: -                cnt_L -= 1 +            if left: +                left -= 1 -                insert_L += 1 -    insert_R = cnt_L -    res = "(" * insert_L + S + ")" * insert_R +                right += 1 +    res = "(" * right + S + ")" * left