#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long> 
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;

const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9;
int n;
string s, t;

int main() {
    ci(n);
    ci(s);
    ci(t);
    vector<int> sind, tind;
    rep(i, n) {
        if (s[n - i - 1] == '1') sind.epb(n - i - 1);
        if (t[n - i - 1] == '1') tind.epb(n - i - 1);
    }
    if (sz(sind) < sz(tind) || sz(sind) % 2 != sz(tind) % 2) {
        co(-1);
        return 0;
    }
    for (int i = 0, e = sz(tind); i < e; i++) {
        if (sind[i] < tind[i]) {
            co(-1);
            return 0;
        }
    }
    ll ans = 0;
    while (!sind.empty()) {
        int i1, i2;
        while (tind.empty() || sind.back() < tind.back()) {
            i1 = sind.back(); sind.pop_back();
            i2 = sind.back(); sind.pop_back();
            ans += i2 - i1;
            if (sind.empty()) break;
        }
        if (!tind.empty() && !sind.empty()) {
            i1 = tind.back(); tind.pop_back();
            i2 = sind.back(); sind.pop_back();
            ans += i2 - i1;
        }
    }
    co(ans);
    return 0;
}

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>

typedef long long int64;

const int N = 500000 + 10;

int n;
char s[N], t[N];

int main() {
    static std::set<int> set;
    std::set<int>::iterator it;
    int i, x;
    int64 tot = 0;

    scanf("%d", &n);
    scanf("%s %s", s + 1, t + 1);
    for (i = 1; i <= n; i++)
        if (s[i] == '1')
            set.insert(i);

    for (i = 1; i <= n; i++) {
        if (s[i] ^ t[i]) {
            it = set.upper_bound(i);
            if (it == set.end()) {
                printf("%d\n", -1);
                return 0;
            }
            x = (*it);
            set.erase(it);

            tot += x - i;
            std::swap(s[i + 1], s[x]);
            s[i + 1] = '0';
        }
    }
    printf("%lld\n", tot);
    return 0;
}