#include<bits/stdc++.h>
using namespace std;
 
int solve()
{
    int n;
    string f, t;
    cin >> n >> f >> t;
    int n1f = 0, n1t = 0;
    for(int i = 0; i < n; ++i)
    {
        if(f[i] == '1')
            n1f++;
        if(t[i] == '1')
            n1t++;
    }
    if(n1f != n1t)
    {
        cout << "-1\n";
        return 0;
    }
    vector<int> mv(n,0);
    int posf=0, post=0;
    while(posf<n && post<n){
        while(f[posf]!='1' && posf<n)
            posf++;
        while(t[post]!='1' && post<n)
            post++;
        f[posf]='0';
        t[post]='0';
        mv[posf]=post-posf;
    }
    // move to the right
    int groupmove=0;
    int sol=0;
    for(int i=0; i<n; i++)
    {
        if(mv[i]>0){
            sol+=mv[i]-groupmove;
            groupmove+=mv[i]-groupmove;
        }
        if(mv[i]==0 && groupmove>0){
            groupmove--;
        }
    }
    // to the left
    groupmove=0;
    for(int i=n-1; i>=0; i--)
    {
        if(mv[i]<0){
            sol+=-mv[i]-groupmove;
            groupmove+=-mv[i]-groupmove;
        }
        if(mv[i]==0 && groupmove>0){
            groupmove--;
        }
    }
 
 
    //debug( mv);
    cout << sol << "\n";
    return 0;
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    for(int test = 0; test < ntest; ++test)
    {
        solve();
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	int n;
	string s, t;
	cin >> n >> s >> t;
	if(count(s.begin(), s.end(), '0') != count(t.begin(), t.end(), '0')){
		cout << "-1\n";
		return 0;
	}
	deque<int> a, b;
	for(auto rep = 0; rep < 2; ++ rep){
		for(auto i = 0; i < n; ++ i){
			if(~s[i] & 1){
				a.push_back(i);
			}
		}
		swap(a, b);
		swap(s, t);
	}
	int res = 0;
	for(auto i = 0; i < (int)a.size(); ++ i){
		if(a[i] != b[i]){
			++ res;
		}
	}
	cout << res << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////