#include <iostream>
#include <vector>

using namespace std;

void solve() {
    int n;
    cin >> n;

    vector<int> xs, ys;
    for (int i = 0; i < n; ++i) {
        char c;
        cin >> c;
        if (c == '0') xs.push_back(i);
    }
    for (int i = 0; i < n; ++i) {
        char c;
        cin >> c;
        if (c == '0') ys.push_back(i);
    }

    if (xs.size() != ys.size()) {
        cout << "-1\n";
        return;
    }

    int ans = 0;
    for (int i = 0; i < (int)xs.size(); ++i) {
        if (xs[i] != ys[i]) ++ans;
    }

    cout << ans << "\n";
}

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

    solve();

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

namespace Tzh{


	typedef long long ll;

	const int maxn=1000010;
	int pos[maxn];

	void work(){
		int n,ans=0;
		cin>>n;
		string a,b;
		cin>>a>>b;
		int cnt=0,tmp=0;
		for(int i=1;i<=n;i++) if(a[i-1]=='0') pos[++cnt]=i;
		for(int i=1;i<=n;i++) if(b[i-1]=='0'){
			tmp++; 
			ans+=(i!=pos[tmp]);
		}
		if(cnt!=tmp) cout<<-1;
		else cout<<ans;
		return ;
	}
}

int main(){
	Tzh::work();
	return 0;
}
