#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
#else

#endif



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Togliere nei problemi con query online

    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    LL res = 0;
    int id = 0;
    for (int i = 0; i < N; i++) {
		if (S[i] == T[i]) continue;
		id = max(i+1, id);
		while (id < N and S[id] == '0') id++;
		if (id == N) {
			cout << -1 << "\n";
			return 0;
		}
		res += id - i;
		S[i] = T[i], S[id] = '0';
	}
	cout << res << "\n";
}
#include<cstdio>
#include<cstring>
#define rg register
const int maxn=1e6+5;
char s[maxn],t[maxn];
int n,cnt1,cnt2,sta1[maxn],sta2[maxn],now;
long long ans;
int main(){
	scanf("%d",&n);
	scanf("%s%s",s+1,t+1);
	for(rg int i=1;i<=n;i++){
		if(s[i]=='1'){
			sta1[++cnt1]=i;
		}
	}
	for(rg int i=1;i<=n;i++){
		if(t[i]=='1'){
			sta2[++cnt2]=i;
		}
	}
	if(cnt1<cnt2 || (cnt1-cnt2)%2){
		printf("-1\n");
		return 0;
	}
	now=1;
	for(rg int i=1;i<=cnt2;i++){
		if(now>cnt1){
			printf("-1\n");
			return 0;
		}
		while(sta1[now]<sta2[i]){
			if(now+2>cnt1){
				printf("-1\n");
				return 0;
			}
			ans+=sta1[now+1]-sta1[now];
			now+=2;
		}
		ans+=sta1[now]-sta2[i];
		now++;
	}
	while(now<cnt1){
		ans+=sta1[now+1]-sta1[now];
		now+=2;
	}
	printf("%lld\n",ans);
	return 0;
}