#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n; cin>>n;
	string s; cin>>s;
	int p=0;
	deque<char> a;
	for(char c: s) {
		a.push_back(c);
		if (c==')') {
			--p;
			if (p<0) { a.push_front('('); ++p; }
		}
		else {
			++p;
		}
	}
	for(char c: a) cout<<c;
	while (p--) cout<<')';
	cout<<endl;
}
