#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	string S;
	cin >> S;

	Int len = S.size();
	Int i = 0;
	Int temp = 0;

	while (i < len) {
		if (S[i] == '(')temp++;
		if (S[i] == ')')temp--;

		if (i + 1 < len && temp < 0 && S[i + 1] == '(') {
			for (Int j = 0; j < abs(temp); j++) {
				S.insert(0, "(");
			}
			i += abs(temp);
			len += abs(temp);
			temp = 0;
		}
		i++;
	}
	
	if (temp < 0) {
		for (Int j = 0; j < abs(temp); j++) {
			S.insert(0, "(");
		}
	}
	else if (temp) {
		for (Int j = 0; j < temp; j++) {
			S.push_back(')');
		}
	}
	/*while (i < len) {
		if (flag == 0 && S[i] == '(') {
			left++;
			i++;
		}
		else if (flag == 0 && S[i] == ')') {
			flag = 1;
			right++;
			i++;
		}
		else if (flag == 1 && S[i] == ')') {
			right++;
			i++;
		}
		else if(flag == 1 && S[i]=='('){
			if (left < right) {
				for (Int j = 0; j < right-left; j++) {
					S.insert(0, "(");
				}
				len += right - left;
				i += right - left;
			}
			else if (left > right) {
				for (Int j = 0; j < left - right; j++) {
					S.push_back(')');
				}
				len += right - left;
			}
			flag = 0;
			left = 1;
			right = 0;
			i++;
		}
	}

	if (left < right) {
		for (Int j = 0; j < right - left; j++) {
			S.insert(0, "(");
		}
	}
	else if (left > right) {
		for (Int j = 0; j < left-right; j++) {
			S.push_back(')');
		}
	}*/

	cout << S << "\n";
}

Measured memory_bytes: 256