#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,int>
#define mp make_pair
#define pll pair<long long,long long>
#define ld long double
#define ull unsigned long long

using namespace std;

const int nax = 4e5 + 11;
int a[nax];
int n;

bool cmp(int x, int y){
    return a[x] < a[y];
}

int score[nax];
int pref[nax];

int OFFSET = 2e5 + 2;

vector<int> ziomki[nax];

char ans[nax];

void reku(int lo, int hi){
    if(lo > hi) return;
    if(score[lo] != score[hi]){
        ans[lo] = '(';
        ans[hi] = ')';
        reku(lo + 1, hi - 1);
        return;
    }
    int cur = pref[lo - 1];
    int idx = pref[lo - 1] + OFFSET;
    auto it = upper_bound(ziomki[idx].begin(), ziomki[idx].end(), lo - 1);
    int nxt = (*it);
    reku(lo, nxt);
    reku(nxt + 1, hi);
}

void solve(){
    cin >> n;
    n *= 2;
    for(int i=1;i<=n;i++) cin >> a[i];
    vector<int> id;
    for(int i=1;i<=n;i++) id.pb(i);
    sort(id.begin(), id.end(), cmp);
    //for(int x : id) cout<<x<<endl;
    for(int i=1;i<=n/2;i++) score[id[i - 1]] = 1;
    for(int i=n/2+1;i<=n;i++) score[id[i - 1]] = -1;
    for(int i=1;i<=n;i++){
        pref[i] = pref[i - 1] + score[i];
        ziomki[pref[i] + OFFSET].pb(i);
    }
    reku(1, n);
    for(int i=1;i<=n;i++) cout<<ans[i];

}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    int tt = 1;
    // cin >> tt;
    while(tt--) solve();


    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 1e5+5;
int a[M],b[M],f[M];
ll pref(int l, int r)
{
	unordered_map<int, vector<int>> vec;
	for(int i=l;i<=r;i++)
	{
		vec[a[i]-i].pb(i);
	}
	ll res = 0;
	for(int i=r;i>=l;i--)
	{
		ll z;
		if(sz(vec[b[i]-i]))
		{
			int id = vec[b[i]-i].back();
			res += (ll)(i-id);
			z = i-id;			
		}
		else
		{
			cout<<"-1\n";
			exit(0);
		}
		vec[a[i]-i].pop_back();
		if(i != r and b[i]-i == b[i+1] - (i+1))
			res-=z;
	}
	return res;
}
ll suff(int l, int r)
{
	unordered_map<int, vector<int>> vec;
	for(int i=r;i>=l;i--)
	{
		vec[a[i]-i].pb(i);
	}
	ll res = 0;
	for(int i=l;i<=r;i++)
	{
		ll z;
		if(sz(vec[b[i]-i]))
		{
			int id = vec[b[i]-i].back();
			res += (ll)(id-i);
			z = id - i;
		}
		else
		{
			cout<<"-1\n";
			exit(0);
		}
		vec[a[i]-i].pop_back();
		if(i != l and b[i]-i == b[i-1] - (i-1))
			res-=z;
	}
	return res;
}
ll solve(int l, int r)
{
	for(int j=l+1;j<=r;j++)
	{
		if(f[j] != -1)
		{
			return pref(l,j-1)+suff(j, r);
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n, L;
	cin>>n>>L;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	a[0] = 0;
	a[n+1] = L+1;
	b[n+1] = L+1;
	for(int i=0;i<=n+1;i++)
	{
		if(a[i] > b[i])
			f[i] = -1;
		if(a[i] < b[i])
			f[i] = 1;
	}
	for(int i=1;i<=n+1;i++)
	{
		if(f[i-1] == 1 and f[i] == -1)
		{
			// cout<<i<<endl;
			cout<<"-1\n";
			return 0;
		}
	}
	int l = 0;
	ll ans = 0;
	for(int i=1;i<=n+1;i++)
	{
		if(f[i] == 0)
		{
			ans += solve(l, i);
			l = i;
		}
	}
	cout<<ans<<"\n";
	return 0;
}