//debug icin gdb kullanmayi dene
#include<bits/stdc++.h>
using namespace std;
#define mods 1000000007
#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef long long int lint;
typedef unsigned long long int ulint;
lint fastpow(lint tab,lint us){
	if(tab==0) return 0;
	if(tab==1) return 1;
	if(us==0) return 1;
	if(us==1) return tab%mods;
	tab%=mods;
	if(us%2==1) return tab*fastpow(tab,us-1)%mods;
	lint a=fastpow(tab,us/2)%mods;
	return a*a%mods;
}
lint t=1;

void solve(){
	lint i,j,k,n,l=0,r=0,cev=0;
	string s1,s2;
	cin>>n>>s1>>s2;
	while(r<n and s1[r]=='0') r++;
	//if (r==n){cout<<-1; return;}
	for(i=0;i<n;i++){
		if(r==i){
			r++;
			while(r<n and s1[r]=='0') r++;
		}
		if(s1[i]!=s2[i]){
			cev+=r-i;
			if (r==n){cout<<-1; return;}
			s1[r]='0';
			while(r<n and s1[r]=='0') r++;
		}
	}
	cout<<cev;





	return;
}

int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	//cin>>t;
	while(t--) solve();
	return 0;
}


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

int gi() {
	char ch='!'; int res=0, f=0;
	while(ch<'0' || ch>'9') { ch=getchar(); if(ch == '-') f=1; }
	while(ch>='0' && ch<='9') res=res*10+ch-'0', ch=getchar();
	return f?-res:res;
}

const int N=5e5+100;
int n; char s[N],t[N]; deque<int> vec;
long long ans;
int main( ){
	scanf("%d",&n);
	scanf("%s%s",s+1,t+1);
	for(int i=1;i<=n;++i)
		if(s[i] == '1') vec.push_back(i);
	for(int i=1;i<=n;++i) {
		if(s[i] == '1' && t[i] == '1') vec.pop_front();
		if(t[i] == '1' && s[i] == '0') {
			if(!vec.size()) puts("-1"), exit(0);
			ans += vec[0]-i; s[vec[0]]='0';
			vec.pop_front();
		}
		if(t[i] == '0' && s[i] == '1') {
			vec.pop_front();
			if(!vec.size()) puts("-1"), exit(0);
			ans += vec[0]-i; s[vec[0]]='0';
			vec.pop_front();
		}
	}
	cout<<ans<<endl;
	return 0;
}