program prob5
    implicit none
    character(105) :: s
    integer :: n
    integer :: m, i, tmp, q, w

    read(*,*) n,s

    m = 0
    tmp = 0
    q = 0
    w = 0
    do i = 1, n
        if(s(i:i) == '(') then
            tmp = tmp + 1
            q = q + 1
        else
            tmp = tmp - 1
            w = w + 1
        end if
        m = min(m, tmp)
    end do
    
    do i = 1, -m
        write(*,'(a)',advance='no') '('
    end do

    q = q - m
    write(*,'(a)',advance='no') trim(adjustl(s))
    do i = 1, q - w
        write(*,'(a)',advance='no') ')'
    end do
    write(*,*) 


    stop
contains
end program prob5