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

#define nl "\n"
#define nf endl
#define ll long long
#define pb push_back
#define _ << ' ' <<

#define INF (ll)1e18
#define mod 998244353
#define maxn 500010

ll i, i1, j, k, k1, n, m, res, flag[10], a, b;
string s, t;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    #if !ONLINE_JUDGE && !EVAL
        ifstream cin("input.txt");
        ofstream cout("output.txt");
    #endif

    cin >> n >> s >> t; s = '#' + s; t = '#' + t;

    for (i = 1; i <= n; i++) {
        if (s[i] == '0') a++;
        if (t[i] == '0') b++;
        if (s[i] == '0' && t[i] == '0' && a == b) res--;
    }

    if (a != b) res = -1;
    else res += a;

    cout << res << nl;

    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#define itn int
#define ll long long
#define yes {puts("Yes");}
#define no {puts("No");}
using namespace std;

ll read(){
	ll a=0,b=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')b=-1;c=getchar();}
	while(c>='0'&&c<='9')a=a*10+c-48,c=getchar();
	return a*b;
}

ll n,ans,m,k;
char s[1000005];
char t[1000005];

int a1[500005],ct1,a2[500005],ct2;

int main(){
	n=read();
	scanf("%s%s",s,t);
	for(int i=0;i<n;i++){
		if(s[i]=='0'){
			a1[++ct1]=i;
		}
		if(t[i]=='0'){
			a2[++ct2]=i;
		}
	}
	if(ct1!=ct2){
		puts("-1");
		return 0;
	}
	int ans=0;
	for(int i=1;i<=ct1;i++){
		if(a1[i]!=a2[i]){
			ans++;
		}
	}
	cout<<ans<<'\n';
	return 0;
}

