#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=5e5+5;
int n,a[N],b[N];
long long ans;

signed main(){
	read(n);
	for(int i=1,x;i<=n;i++){
		scanf("%1d",&x);
		if(x) a[++*a]=i;
	}
	for(int i=1,x;i<=n;i++){
		scanf("%1d",&x);
		if(x) b[++*b]=i;
	}
	if(*a<*b||*a-*b&1) return write(-1),0;
	int i=1;
	for(int j=1;j<=*b;i++,j++){
		while(i<=*a&&a[i]<b[j]) ans+=a[i+1]-a[i],i+=2;
		if(i>*a) return write(-1),0;
		ans+=a[i]-b[j];
	}
	while(i<=*a) ans+=a[i+1]-a[i],i+=2;
	write(ans);
}
#include <bits/stdc++.h>
using namespace std;
const int maxn=500005;
char s[maxn];
int pos1[maxn],n1,pos2[maxn],n2;
int main()
{
    int i,j;
    long long ans=0;
    scanf("%*d%s",s);
    for(i=0,n1=0;s[i];i++)
        if(s[i]=='1')
            pos1[n1++]=i;
    scanf("%s",s);
    for(i=0,n2=0;s[i];i++)
        if(s[i]=='1')
            pos2[n2++]=i;
    if(((n1^n2)&1) || n1<n2) { printf("-1\n"); return 0; }
    for(i=0,j=0;i<n1;)
        if(j>=n2 || pos1[i]<pos2[j]) ans+=pos1[i+1]-pos1[i],i+=2;
        else ans+=pos1[i]-pos2[j],i++,j++;
    printf("%lld\n",(j>=n2)?ans:-1ll);
    return 0;
}