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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    vector <int> vs, vt;
    rep(i, n) if (s[i] == '1') vs.pb(i);
    rep(i, n) if (t[i] == '1') vt.pb(i);
    if (vs.size() < vt.size() || (vs.size() - vt.size()) % 2 == 1) {
        printf("-1\n");
        return 0;
    }
    ll ans = 0;
    int j = 0;
    rep(i, vs.size()) {
        if (j < vt.size() && vs[i] >= vt[j]) {
            ans += vs[i] - vt[j];
            ++ j;
        } else {
            if (i + 1 == vs.size()) {
                printf("-1\n");
                return 0;
            }
            ans += vs[i + 1] - vs[i];
            ++ i;
        }
    }
    if (j < vt.size()) {
        printf("-1\n");
        return 0;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int pre = 0;
    queue<int> stk;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') {
            stk.push(i);
        }
    }
    long long ans = 0;
    bool ok = true;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') {
            stk.pop();
            if (t[i] == '0') {
                if (stk.empty()) {
                    ok = false;
                    break;
                }
                ans += stk.front() - i;
                s[stk.front()] = '0';
                stk.pop();
            }
        } else {
            if (t[i] == '1') {
                if (stk.empty()) {
                    ok = false;
                    break;
                }
                ans += stk.front() - i;
                s[stk.front()] = '0';
                stk.pop();
            }
        }
    }
    if (ok) {
        if (stk.size() % 2) {
            ok = false;
        } else {
            while (!stk.empty()) {
                int x = stk.front();
                stk.pop();
                int y = stk.front();
                ans += y - x;
            }
        }
    }
    cout << (ok ? ans : -1) << endl;
}
