program main
    implicit none
    integer n, lowest, now, i
    character(len=300):: s, first, end_

    read*, n, s
    s = trim(s)
    lowest=0; now=0
    do i = 1,n
        if(s(i:i) == '(')then
            now = now + 1
        else
            now = now - 1
        end if
        lowest = min(lowest, now)
    end do
    ! print*, now, lowest
    first = ''
    end_ = ''

    do i = 1, -lowest
        first = trim(first) // '('
    end do

    do i = 1, now-lowest
        end_ = trim(end_) // ')'
    end do

    print'(a)', trim(first) // trim(s) // trim(end_)

    
end program