/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Pine1999
 */

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

void solve(std::istream& in, std::ostream& out) {
    int n; in >> n;
    string s, t;
    in >> s >> t;
    queue<int> spos, tpos;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') spos.push(i);
        if (t[i] == '1') tpos.push(i);
    }
    long long ans = 0;
    while (!spos.empty() && !tpos.empty()) {
        int si = spos.front();
        int ti = tpos.front();
        if (si == ti) {
            spos.pop();
            tpos.pop();
        } else if (si < ti) {
            spos.pop();
            if (spos.empty()) {
                out << -1 << '\n';
                return;
            }
            int nsi = spos.front();
            spos.pop();
            //cout << nsi << " " << si << '\n';
            ans += nsi - si;
        } else {
            spos.pop();
            tpos.pop();
            //cout << si << " " << ti << '\n';
            ans += si - ti;
        }
    }
    while (!spos.empty()) {
        int si = spos.front();
        spos.pop();
        if (spos.empty()) {
            out << -1 << '\n';
            return;
        }
        int nsi = spos.front();
        spos.pop();
        //cout << nsi << " " << si << '\n';
        ans += nsi - si;
    }
    if (!tpos.empty() || !spos.empty()) {
        out << -1 << '\n';
        return;
    }
    out << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solve(in, out);
    return 0;
}
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
char S[505050], T[505050];
vector<int> A, B;

int main()
{
	scanf("%d%s%s", &N, S, T);

    for (int i = 0; i < N; ++i) if (S[i] == '1') A.push_back(i);
    for (int i = 0; i < N; ++i) if (T[i] == '1') B.push_back(i);

    int a = 0, b = 0;
    i64 ret = 0;
    while (a < A.size() || b < B.size()) {
        if (a == A.size()) {
            ret = -1;
            break;
        }
        if (b < B.size() && A[a] >= B[b]) {
            ret += A[a] - B[b];
            ++a;
            ++b;
            continue;
        } else {
            if (a + 2 > A.size()) {
                ret = -1;
                break;
            }
            ret += A[a + 1] - A[a];
            a += 2;
            continue;
        }
    }
    printf("%lld\n", ret);
	return 0;
}
