#

# 　　  ⋀_⋀　 

#　　  (･ω･)  

# .／ Ｕ ∽ Ｕ＼

#  │＊　合　＊│

#  │＊　格　＊│ 

#  │＊　祈　＊│ 

#  │＊　願　＊│ 

#  │＊　　　＊│ 

#      ￣

#

import sys

input=sys.stdin.readline

inf=float('inf')

mod = 10**9+7

def INT_(n): return int(n)-1

def MI(): return list(map(int,input().split()))

def MF(): return list(map(float, input().split()))

def MI_(): return list(map(INT_,input().split()))

def LI(): return list(MI())

def LI_(): return [int(x) - 1 for x in input().split()]

def LF(): return list(MF())

def LIN(n:int): return [eval(input()) for _ in range(n)]

def LLIN(n: int): return [LI() for _ in range(n)]

def LLIN_(n: int): return [LI_() for _ in range(n)]

def LLI(): return [list(map(int, l.split() )) for l in eval(input())]

def I(): return int(eval(input()))

def F(): return float(eval(input()))

def ST(): return input().replace('\n', '')

def main():

    N = I()

    S = ST()

    imos = []

    for s in S:

        if s == "(":

            imos.append(1)

        else:

            imos.append(-1)

    status = [0]

    head = ""

    tail = ""

    for imo in imos:

        appp = status[-1] + imo

        if appp < 0:

            head += "("

            appp = 0

        status.append(appp)

    if status[-1] > 0:

        tail = ")" * status[-1]

    print((head+S+tail))

if __name__ == '__main__':

    main()
#

# 　　  ⋀_⋀　 

#　　  (･ω･)  

# .／ Ｕ ∽ Ｕ＼

#  │＊　合　＊│

#  │＊　格　＊│ 

#  │＊　祈　＊│ 

#  │＊　願　＊│ 

#  │＊　　　＊│ 

#      ￣

#

import sys

sys.setrecursionlimit(10**6)

input=sys.stdin.readline

from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ

from heapq import heappop, heappush, heappushpop

from collections import Counter,defaultdict,deque

from itertools import accumulate,permutations,combinations,product,combinations_with_replacement

from bisect import bisect_left,bisect_right

from copy import deepcopy

from fractions import gcd

from random import randint

def ceil(a,b): return (a+b-1)//b

inf=float('inf')

mod = 10**9+7

def pprint(*A): 

    for a in A:     print(*a,sep='\n')

def INT_(n): return int(n)-1

def MI(): return map(int,input().split())

def MF(): return map(float, input().split())

def MI_(): return map(INT_,input().split())

def LI(): return list(MI())

def LI_(): return [int(x) - 1 for x in input().split()]

def LF(): return list(MF())

def LIN(n:int): return [I() for _ in range(n)]

def LLIN(n: int): return [LI() for _ in range(n)]

def LLIN_(n: int): return [LI_() for _ in range(n)]

def LLI(): return [list(map(int, l.split() )) for l in input()]

def I(): return int(input())

def F(): return float(input())

def ST(): return input().replace('\n', '')

def main():

    N=I()

    S=ST()

    head = 0

    tail = 0

    c,e = 0,0

    for s in S:

        if s=="(":

            c += 1

        else:

            e += 1

        if c<e:

            head += e-c

            e=c

    if c>e:

        tail = c-e

    print(head * "(" + S + tail * ")")

        

if __name__ == '__main__':

    main()

    #H*W = Sになるような最大値最小の(H,W)を求める

    # S=I()

    # x1,y1 = 0,0

    # x2,y3 = 0,0



    # x2,y2





    # S=ST()

    # ans = 0

    # for i in range(len(S)):

    #     for it in combinations([i for i in range(len(S))], i):

    #         before = 0

    #         for j in it:

    #             print(int(S[before:j+1]), before,j)

    #             ans += int(S[before:j+1])

    #             before = j+1

    #         try:

    #             ans += int(S[before:])

    #         except:

    #             pass

    #         print(ans)

    # print(ans)

#
# 　　  ⋀_⋀
# 　　  (･ω･)
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│
#  │＊　祈　＊│
#  │＊　願　＊│
#  │＊　　　＊│
#      ￣
#
import sys

input = sys.stdin.readline
inf = float("inf")
mod = 10**9 + 7


def INT_(n):
    return int(n) - 1


def MI():
    return list(map(int, input().split()))


def MF():
    return list(map(float, input().split()))


def MI_():
    return list(map(INT_, input().split()))


def LI():
    return list(MI())


def LI_():
    return [int(x) - 1 for x in input().split()]


def LF():
    return list(MF())


def LIN(n: int):
    return [eval(input()) for _ in range(n)]


def LLIN(n: int):
    return [LI() for _ in range(n)]


def LLIN_(n: int):
    return [LI_() for _ in range(n)]


def LLI():
    return [list(map(int, l.split())) for l in eval(input())]


def I():
    return int(eval(input()))


def F():
    return float(eval(input()))


def ST():
    return input().replace("\n", "")


def main():
    N = I()
    S = ST()
    imos = []
    for s in S:
        if s == "(":
            imos.append(1)
        else:
            imos.append(-1)
    status = [0]
    head = ""
    tail = ""
    for imo in imos:
        appp = status[-1] + imo
        if appp < 0:
            head += "("
            appp = 0
        status.append(appp)
    if status[-1] > 0:
        tail = ")" * status[-1]
    print((head + S + tail))


if __name__ == "__main__":
    main()

#
# 　　  ⋀_⋀
# 　　  (･ω･)
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│
#  │＊　祈　＊│
#  │＊　願　＊│
#  │＊　　　＊│
#      ￣
#
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import (
    accumulate,
    permutations,
    combinations,
    product,
    combinations_with_replacement,
)
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b):
    return (a + b - 1) // b


inf = float("inf")
mod = 10**9 + 7


def pprint(*A):
    for a in A:
        print(*a, sep="\n")


def INT_(n):
    return int(n) - 1


def MI():
    return map(int, input().split())


def MF():
    return map(float, input().split())


def MI_():
    return map(INT_, input().split())


def LI():
    return list(MI())


def LI_():
    return [int(x) - 1 for x in input().split()]


def LF():
    return list(MF())


def LIN(n: int):
    return [I() for _ in range(n)]


def LLIN(n: int):
    return [LI() for _ in range(n)]


def LLIN_(n: int):
    return [LI_() for _ in range(n)]


def LLI():
    return [list(map(int, l.split())) for l in input()]


def I():
    return int(input())


def F():
    return float(input())


def ST():
    return input().replace("\n", "")


def main():
    N = I()
    S = ST()
    head = 0
    tail = 0
    c, e = 0, 0
    for s in S:
        if s == "(":
            c += 1
        else:
            e += 1
        if c < e:
            head += e - c
            e = c
    if c > e:
        tail = c - e
    print(head * "(" + S + tail * ")")


if __name__ == "__main__":
    main()
    # H*W = Sになるような最大値最小の(H,W)を求める
    # S=I()
    # x1,y1 = 0,0
    # x2,y3 = 0,0
    # x2,y2
    # S=ST()
    # ans = 0
    # for i in range(len(S)):
    #     for it in combinations([i for i in range(len(S))], i):
    #         before = 0
    #         for j in it:
    #             print(int(S[before:j+1]), before,j)
    #             ans += int(S[before:j+1])
    #             before = j+1
    #         try:
    #             ans += int(S[before:])
    #         except:
    #             pass
    #         print(ans)
    # print(ans)

+sys.setrecursionlimit(10**6) +from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ +from heapq import heappop, heappush, heappushpop +from collections import Counter, defaultdict, deque +from itertools import ( +    accumulate, +    permutations, +    combinations, +    product, +    combinations_with_replacement, +) +from bisect import bisect_left, bisect_right +from copy import deepcopy +from fractions import gcd +from random import randint + + +def ceil(a, b): +    return (a + b - 1) // b + + + + +def pprint(*A): +    for a in A: +        print(*a, sep="\n") -    return list(map(int, input().split())) +    return map(int, input().split()) -    return list(map(float, input().split())) +    return map(float, input().split()) -    return list(map(INT_, input().split())) +    return map(INT_, input().split()) -    return [eval(input()) for _ in range(n)] +    return [I() for _ in range(n)] -    return [list(map(int, l.split())) for l in eval(input())] +    return [list(map(int, l.split())) for l in input()] -    return int(eval(input())) +    return int(input()) -    return float(eval(input())) +    return float(input()) -    imos = [] +    head = 0 +    tail = 0 +    c, e = 0, 0 -            imos.append(1) +            c += 1 -            imos.append(-1) -    status = [0] -    head = "" -    tail = "" -    for imo in imos: -        appp = status[-1] + imo -        if appp < 0: -            head += "(" -            appp = 0 -        status.append(appp) -    if status[-1] > 0: -        tail = ")" * status[-1] -    print((head + S + tail)) +            e += 1 +        if c < e: +            head += e - c +            e = c +    if c > e: +        tail = c - e +    print(head * "(" + S + tail * ")") +    # H*W = Sになるような最大値最小の(H,W)を求める +    # S=I() +    # x1,y1 = 0,0 +    # x2,y3 = 0,0 +    # x2,y2 +    # S=ST() +    # ans = 0 +    # for i in range(len(S)): +    #     for it in combinations([i for i in range(len(S))], i): +    #         before = 0 +    #         for j in it: +    #             print(int(S[before:j+1]), before,j) +    #             ans += int(S[before:j+1]) +    #             before = j+1 +    #         try: +    #             ans += int(S[before:]) +    #         except: +    #             pass +    #         print(ans) +    # print(ans)