#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n;
	string s, t;
	cin >> n >> s >> t;
	int bal = 0;
	ll ans = 0;
	for(int i = 0; i < n; i++) {
		if(t[i] == '1') bal++, ans -= i;
		if(s[i] == '1') {
			if(bal > 0) bal--, ans += i;
			else bal++, ans -= i;
		}
	}
	if(bal) cout << -1 << endl;
	else cout << ans << endl;

}


#line 2 "/home/defineprogram/Desktop/Library/template/template.cpp"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<ll,ll>
#define len(s) (ll)s.size()
 
template<class T,class U> inline bool chmin(T &a, U b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T,class U> inline bool chmax(T &a, U b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr ll inf = 3e18;
#line 3 "/home/defineprogram/Desktop/Library/structure/UnionFind.cpp"

class UnionFind{
	int N;
	vector<int>par,siz;
public:
	int find(int x){
		assert(x<N);
		return (par[x]==x?x:par[x]=find(par[x]));
	}
	void merge(int x,int y){
		assert(x<N&&y<N);
		x=find(x);y=find(y);
		if(x==y)return;
		if(siz[x]>siz[y])swap(x,y);
		par[x]=y;siz[y]+=siz[x];
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	int size(int x){
		return siz[find(x)];
	}
	UnionFind(int N):N(N),siz(N,1),par(N){
		iota(all(par),0);
	}
};

/*
@brief Union Find
@docs docs/UnionFind.md
*/
#line 3 "main.cpp"

int N;
string S,T;
vector<int>zero,one;
bool t[500005];
int main(){
    cin>>N>>S>>T;
    int now=0,now2=0;
    rep(i,N){
        now^=S[i]-'0';
        now2^=T[i]-'0';t[i]=now2;
        if(!now)zero.push_back(i);
        else one.push_back(i);
    }
    ll ans=0;int cur=0;
    int idx0=0,idx1=0;
    bool flag0=false,flag1=false;
    rep(i,N){
        chmax(cur,i);
        while(idx0<len(zero)&&zero[idx0]<cur){idx0++;flag0=false;}
        while(idx1<len(one)&&one[idx1]<cur){idx1++;flag1=false;}
        if(!t[i]){
            if(idx0==len(zero)){cout<<"-1\n";return 0;}
            if(!flag0)ans+=zero[idx0]-i;
            flag0=true;
            chmax(cur,zero[idx0]);
        }else {
            if(idx1==len(one)){cout<<"-1\n";return 0;}
            if(!flag1)ans+=one[idx1]-i;
            flag1=true;
            chmax(cur,one[idx1]);
        }
    }
    cout<<ans<<endl;
}
