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

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 400005

int n;
int a[MAXN];
priority_queue<ii> pq;
char type[2];
bool impt[MAXN];
string ans;

int main() {
	scanf("%d", &n);
	REP (i, 0, n * 2) {
		scanf("%d", &a[i]);
		pq.push(MP(a[i], i));
	}
	REP (i, 0, n) {
		auto [_, id] = pq.top(); pq.pop();
		impt[id] = 1;
	}
	int cnt = 0;
	REP (i, 0, n * 2) {
		if (cnt == 0) {
			type[impt[i]] = '(';
			type[1 - impt[i]] = ')';
		}
		ans += type[impt[i]];
		if (type[impt[i]] == '(') {
			cnt++;
		} else {
			cnt--;
		}
	}
	printf("%s\n", ans.c_str());
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
 
const long long SZ = 1e5 + 7;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long MOD = 998244353;
 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
 
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << x;}
void __print(const char *x) {cerr << x;}
void __print(const string &x) {cerr << x;}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first); cerr << ", "; __print(x.second);
    cerr << '}';
}
 
template<typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
    {
        cerr << (f++ ? ", " : "");
        __print(i);
    }
    cerr << "}";
}
void _print()
{
    cerr << "]\n";
}
 
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
    {
        cerr << ", ";
    }
    _print(v...);
}
 
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define  dbg(x...)
#endif
 
#define pb                  push_back
#define mp                  make_pair
 
#define fi                  first
#define se                  second
 
#define endl                '\n'
#define sz(x)               (long long)x.size()
 
#define all(c)              (c).begin(), (c).end()
#define allr(c)             (c).rbegin(), (c).rend()
 
#define Max(a,b)            ((a > b) ? a : b)
#define Min(a,b)            ((a < b) ? a : b)
 
#define ci(X)               long long X; cin >> X
#define cii(X, Y)           long long X, Y; cin >> X >> Y
#define ciii(X, Y, Z)       long long X, Y, Z; cin >> X >> Y >> Z
 
long long                   tc_cnt = 1;
#define ons()               cout << "Case #" << tc_cnt ++ << ": ";
 
#define flash               ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
#define forn(i, l, r)       for(long long i = l; i < (r); i++)
#define forr(i, l, r)       for(long long i = l; i >= (r); i--)
 
#define mem0(X)             memset((X), 0, sizeof((X)))
#define mem1(X)             memset((X), -1, sizeof((X)))
#define setbits(x)          __builtin_popcountll(x)
 
ll powermod(ll a, ll b)
{
    ll ans = 1;
    while (b)
    {
        if (b & 1) ans = (ans * a) % mod;
        b = b / 2;
        a = (a * a) % mod;
    }
    return ans;
}
 
ll gcd(ll a, ll b)
{
    if (b == 0) return a;
    return gcd(b, a % b);
}
 
ll lcm(ll a, ll b)
{
    return (a / gcd(a, b)) * b;
}
 
bool palin(string s)
{
    ll l = 0;
    ll r = sz(s) - 1;
    while(l < r)
    {
        if(s[l ++] != s[r --])
        {
            return false;
        }
    }
    return true;
}
int stoint(string change){
    stringstream geek(change);
    int x=0;
    geek >> x;
    return x;
}
void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    string t;
    cin >> t;
    if(s==t){
        cout << "0" << endl;
        return;
    }
    string sf=s;
    string tf=t;
    sort(all(sf));
    sort(all(tf));
    if(sf!=tf){
        cout << "-1" << endl;
        return;
    }
    int cnt=0;
    vector <int> ain,bin;
    for(int i=0;i<n;i++){
        if(s[i]=='0'){
            ain.push_back(i);
        }
        if(t[i]=='0'){
            bin.push_back(i);
        }
    }
    if(ain.size()!=bin.size()){
        cout << "-1" << endl;
    }
    forn(i,0,ain.size()){
        if(ain[i]!=bin[i]){
            cnt++;
        }
    }
cout << cnt << endl;
    

}

int32_t main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("new.txt", "w", stdout);
#endif
    flash;
    int t=1; 
   // cin>>t;
    while(t--) {
      solve();
    }
}