#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
// using namespace atcoder;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    

    ll ans = 0;

    int amari = -1;
    queue<int> que;
    rep(i,n){
        if(s[i] == '0' && t[i] == '1'){
            que.push(i);
        }

        if(s[i] == '1' && t[i] == '0'){
            if(amari!=-1&&que.size()>0){
                if(que.front() < amari){
                    ans += i - que.front();
                    que.pop();
                }else{
                    ans += i - amari;
                    amari = -1;
                }
            }else if(amari != -1){
                ans += i - amari;
                amari = -1;
            }else if(que.size()>0){
                ans += i - que.front();
                que.pop();
            }else{
                amari = i;
            }
        }
    }

    if(amari != -1) ans = -1;
    if(que.size() > 0) ans = -1;

    cout << ans << endl;
    return 0;
}



#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e2 + 10;

int n, a[N];

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	
	int mi = INT_MAX;
	for (int i = 1; i < (1 << n); i++)
	{
		bitset<25> st(i);
		
		int sum = 0, tot = 0;
		for (int j = 0; j < n; j++)
		{
			sum |= a[j];
			if (st[j] == 1) tot ^= sum, sum = 0;
		}
		tot ^= sum;
		mi = min(mi, tot);
	}
	cout << mi << "\n";
	
	return 0;
}