#include<bits/stdc++.h>
using ll = int_fast64_t;

int main(){
	int n;
	scanf("%d", &n);
	char s[n+1], t[n+1];
	scanf("%s %s", s, t);

	ll ans = 0;
	int dis = 0;
	while(dis<n && t[dis]!='1') dis++;

	int prev = -1;
	for(int i=0; i<n; i++){
		if(s[i]=='1') {
			if(prev>=0){
				s[prev] = s[i]= '0';
				ans += i-prev;
				prev = -1;
				continue;
			}

			if(dis>i) prev = i;
			else{
				s[i] = '0';
				s[dis] = '1';
				ans += i-dis;
				dis++;
				while(dis<n && t[dis]!='1') dis++;
			}
		}
	}

	bool ok = true;
	for(int i=0; i<n; i++){
		if(s[i]!=t[i]) ok = false;
	}

	if(ok) printf("%ld\n", ans);
	else puts("-1");
	return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




using ll = long long;



const int maxn = 5e5 + 10;
int n;
string s, t;

const int inf = 1e9;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);


    cin>>n;
    cin>>s;
    cin>>t;

    ll ans = 0;

    for (int i=0,j=-1; i<n; i++) {
	
	if (s[i]!=t[i]) {
	    j=max(j,i+1);
	    while (j<n && s[j]!='1') {
		s[j]='0';
		j++;
	    }
	    
	    if (j==n) out(-1);
	    ans += ll(j-i);
	    s[j]=(1^s[j]);
	    j++;

	    s[i]=(1^s[i]);
	}

	// cout<<i<<": "<<j<<endl;
	// watch(s);
    }

    out(ans);
			 

    return 0;
}
