#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
#define per(i,n) for(ll (i)=(n)-1;(i)>=0;--(i))
#ifdef LOCAL
#define debug(x) cerr<<__LINE__<<": "<<#x<<"="<<x<<endl;
#define debugALL(x) cerr<<__LINE__<<": "<<#x<<"=";for(auto i=(x).begin();i!=--(x).end();i++)cerr<<*i<<" ";cerr<<*--(x).end()<<endl;
#else
#define debug(x) true
#define debugALL(x) true
#endif
using namespace std;

int main(){
    ll n;
    cin>>n;
    vector<P> a;
    rep(i,2*n){
        ll ai;
        cin>>ai;
        a.emplace_back(ai,i);
    }
    sort(a.begin(),a.end());
    V d(2*n,0);
    rep(i,n){
        d[a[i].second]=0;
        d[a[i+n].second]=1;
    }
    debugALL(d);
    string ans;
    ll res=0;
    stack<ll> sta;
    rep(i,2*n){
        if(res==0){
            ans.push_back('(');
            res++;
            sta.push(d[i]);
        }else{
            if(sta.top()==d[i]){
                sta.push(d[i]);
                res++;
                ans.push_back('(');
            }else{
                sta.pop();
                res--;
                ans.push_back(')');
            }
        }
    }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a,b,sizeof(a))
#define vi vector<int>
#define vii vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define w(x)  int x; cin>>x; while(x--)
#define in(a) for(auto &x: a)cin>>x;
#define out(a) for(auto x: a){cout<<x<<' ';}cout<<'\n';
#define inf 1000000000
//#define mm 1000000007 998244353
void print(bool n){if(n)cout<<"YES";else cout<<"NO";cout<<'\n';}
signed main(){
	fastio
	int n;
	cin>>n;
	int p[n];
	fill(p,0);
	bool a[n];
	bool b[n];
	char x;
	vi aa,bb;
	rep(i,0,n){
		cin>>x;
		a[i]=(x=='1');
		if(!a[i])aa.pb(i);
	}
	rep(i,0,n){
		cin>>x;
		b[i]=(x=='1');
		if(!b[i])bb.pb(i);
	}
	if(aa.size()!=bb.size()){
		cout<<-1;return 0;
	}
	int r=0;
	bool arr[n];
	fill(arr,0);
	rep(i,0,aa.size()){
		if(aa[i]==bb[i])continue;
		if(aa[i]<bb[i]){
			rep(j,aa[i],bb[i]+1){
				if(a[j]==0)arr[j]=1;
			}
		}
		if(aa[i]>bb[i]){
			for(int j=aa[i];j>=bb[i];j--){
				if(a[j]==0)arr[j]=1;
			}
		}
	}
	int sum=0;
	rep(i,0,n)sum+=arr[i];
	cout<<sum;
	return 0;
}