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

int main() {
	int N;
	cin >> N;
	string S, T;
	cin >> S >> T;
	vector<int>s;
	for (int i = 0; i < N; ++i) {
		if ('1' == S[i]) {
			s.push_back(i);
		}
	}
	vector<int>t;
	int tcount = 0;
	for (int i = 0; i < N; ++i) {
		if ('1' == T[i]) {
			t.push_back(i);
		}
	}
	if (t.size() % 2 != s.size() % 2) {
		cout << -1 << endl;
		return 0;
	}
	if (s.size() < t.size()) {
		cout << -1 << endl;
		return 0;
	}
	vector<int>newt;
	int j = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (j >= t.size()) {
			newt.push_back(s[i]);
			newt.push_back(s[i]);
			++i;
			continue;
		}
		if (s[i] < t[j]) {
			newt.push_back(s[i]);
			newt.push_back(s[i]);
			++i;
		}
		else {
			newt.push_back(t[j]);
			j++;
		}
	}
	if (j != t.size()) {
		cout << -1 << endl;
		return 0;
	}
	long long sumS = 0;
	for (int i = 0;i<s.size();++i) {
		sumS += s[i];
		//cout << s[i];
	}
	//cout << endl;
	long long sumT = 0;
	for (int i = 0; i <newt.size(); ++i) {
		sumT += newt[i];
		//cout << newt[i];
	}
	//cout << endl;
	cout << sumS - sumT << endl;
	return 0;
}
#include<bits/stdc++.h>
typedef long long LL;
typedef double dl;
#define opt operator
#define pb push_back
const LL maxn=1e6+9,mod=998244353,inf=0x3f3f3f3f;
LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
	}return x*f;
}
void Chkmin(LL &x,LL y){
	if(y<x) x=y;
}
void Chkmax(LL &x,LL y){
	if(y>x) x=y;
}
LL add(LL x,LL y){
	return x+=y,x>=mod?x-mod:x;
}
LL dec(LL x,LL y){
	return x-=y,x<0?x+mod:x;
}
LL mul(LL x,LL y){
	return 1ll*x*y%mod;
}
LL Pow(LL base,LL b){
	LL ret(1); while(b){
		if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1;
	}return ret;
}
LL n,tot1,tot2;
LL a[maxn],b[maxn];
char s[maxn],t[maxn];
int main(){
	n=Read();
	scanf(" %s",s+1); scanf(" %s",t+1);
	for(LL i=1;i<=n;++i) if(s[i]=='1') a[++tot1]=i;
	for(LL i=1;i<=n;++i) if(t[i]=='1') b[++tot2]=i;
	if(tot1<tot2){
		puts("-1");
		return 0;
	}
	LL flag(1);
	LL j(1);
	LL ans(0);
	for(LL i=1;i<=tot2;++i){
		if(j>tot1){
			flag=0; break;
		}
		if(a[j]==b[i]){
			++j;
			continue;
		}
		if(a[j]<b[i]){
			if(j==tot1){
				flag=0; break;
			}
			ans+=(a[j+1]-a[j]);
			j+=2; --i;
			continue;
		}
		if(a[j]>b[i]){
			ans+=(a[j]-b[i]); ++j;
		}
	}
	if(!flag){
		puts("-1"); return 0;
	}
	if(j>tot1){
	    printf("%lld\n",ans); return 0;
    }
    if((tot1-j+1)&1){
    	puts("-1"); return 0;
	}
	for(LL i=j;i<=tot1;i+=2){
		ans+=(a[i+1]-a[i]);
	}
	printf("%lld\n",ans);
	return 0;
}