#include<iostream>
#include<cstdio>
#include<map>
#include<bitset>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<ctime>
using namespace std;
#define M 500005
#define N 1000005
#define MP make_pair
#define debug() cerr<<"Why So Serious?"<<endl
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T>void Rd(T &x){
	x=0;static char c;
	while(c=getchar(),c<48);
	do x=(x<<1)+(x<<3)+(c^48);
	while(c=getchar(),c>47);
}
int n;
char str1[M],str2[M];
int tot1,tot2;
int A[M],B[M];
int main(){
	Rd(n);
	scanf("%s%s",str1,str2);
	for(int i=0;i<n;++i){
		if(str1[i]=='1')A[++tot1]=i;
		if(str2[i]=='1')B[++tot2]=i;
	}
	if(tot1!=tot2){
		puts("-1");
		return 0;
	}
	int ans=0;
	for(int i=1;i<=tot1;i++)if(A[i]!=B[i]){
		int j=i+1;
		bool f=A[i]<B[i];
		for(;j<=tot1&&(A[j]<B[j])==f;++j);
		if(f){
			ans+=abs(B[i]-A[i]);
			for(i++;i<j;++i){
				ans+=B[i]-max(B[i-1]+1,A[i]);
			}
			i--;
		}else {
			j--;
			ans+=abs(B[j]-A[j]);
			for(int k=j-1;k>=i;--k){
				ans+=min(A[k],B[k+1]-1)-B[k];
			}
			i=j;
		}
	}
	printf("%d\n",ans);
	return 0;
}
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rrep(i,n) for(ll i=n-1; i>=0; i--)
#define fi first
#define se second
#define pcnt __builtin_popcountll
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
string zero_padding(int val, int nf){ ostringstream sout;sout << setfill('0') << setw(nf) << val; return sout.str();};
const ld eps = 1e-10;
ull mo = 1000000007;
ld PI=asin(1)*2;
//using namespace atcoder;
ll Scnt[2];
ll Tcnt[2];
string S,T;
ll N;

// ll dfs(ll id){

// }

int main(){ 
    cin >> N >> S >> T;
    rep(i,N){
        Scnt[S[i] - '0']++;
        Tcnt[T[i] - '0']++;
    }
    set<ll> S_st, T_st;
    rep(i,N){
        if(S[i] == '0'){
            S_st.insert(i);
        }
        if(T[i] == '0'){
            T_st.insert(i);
        }
    }
    if(!(Scnt[0] == Tcnt[0] && Scnt[1] == Tcnt[1])) drop(-1);
    ll ans = 0;
    rep(i,N){
        if(S[i] == T[i]) continue;
        if(S[i] == '1'){
            auto itr = S_st.lower_bound(i+1);
            ll next = *itr;
            S_st.erase(itr);
            ans++;
            S[next] = '1';
        }else if(T[i] == '1'){
            auto itr = T_st.lower_bound(i+1);
            ll next = *itr;
            T_st.erase(itr);
            ans++;
            T[next] = '1';
        }
    }
    cout << ans << endl;
}
