//
//  main.cpp
//  test
//
//  Created by wyzwyz on 2021/5/13.
//

#include<cstdio>
#include<cctype>

#define maxn 505505

template<class T>

inline T read(){
    T r=0,f=0;
    char c;
    while(!isdigit(c=getchar()))f|=(c=='-');
    while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar();
    return f?-r:r;
}

template<class T>

inline T min(T a,T b){
    return a<b?a:b;
}

int n,s_a[2],a[2][maxn];

char s[maxn],t[maxn];

int main(){
    n=read<int>();
    scanf("%s\n%s",s+1,t+1);
    for(int i=1;i<=n;i++){
        if(s[i]=='0')a[0][++s_a[0]]=i;
        if(t[i]=='0')a[1][++s_a[1]]=i;
    }
    if(s_a[0]^s_a[1])return puts("-1"),0;
    int ans=0;
    for(int i=1;i<=s_a[0];i++)
    ans+=(a[0][i]-a[1][i])!=0;
    printf("%d\n",ans);
    return 0;
}
#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void pr(pair<ll,ll> p){
	cout << "[" << p.ff << ", " << p.ss << "]\n";
}
void pr(set<pair<ll,ll>> s){
	for(auto u : s){
		pr(u);
	}
} 
int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	fast;
	ll T = 1, i, j;
	
	//cin >> T;
	while (T--) {
		ll n;
		cin >> n;
		string s, t;
		cin >> s >> t;
		ll ca = 0;
		for(auto u : s){
			ca += (u - '0');
		}
		//cout << ca << endl;
		for(auto u : t){
			ca -= (u - '0');
		}
		if(ca != 0){
			cout << -1;
			return 0;
		}
		vector<ll> a, b;
		for(i =0 ; i < n; i++){
			if(s[i] == '0'){
				a.pb(i);
			}
			if(t[i] == '0'){
				b.pb(i);
			}
		}
		ll ans = 0;
		for(i = 0; i < a.size(); i++){
			ans += (a[i] != b[i])
;		}
		cout << ans << endl;
	}
	return 0;
}