import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.container;
import std.array;
import std.math;
import std.range;
import std.typecons;
import std.ascii;

bool check(string s)
{
  int index = 0;
  foreach (c; s) {
    if (c=='(') {
      ++index;
    } else {
      if (index == 0) {
        return false;
      }
      --index;
    }
  }
  return index  == 0;
}

void main()
{
  int n = readln.chomp.to!int;
  string s = readln.chomp;
  string sub, ans;
  int index = 0;
  foreach (c; s) {
    final switch(c) {
      case '(':
        ans ~= sub;
        ans ~= '(';
        sub = "";
        ++index;
        break;
      case ')':
        if (index == 0) {
          sub = sub ~ ")";
          ans = "(" ~ ans;
        } else {
          sub = sub ~ ")";
          --index;
        }
        break;
    }
  }
  //()())))((()(()))(((((
  foreach (i; 0..index) {
    sub ~= ")";
  }
  ans ~= sub;
  assert(ans.check);
  writeln = ans;
}
