#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

void solve() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    queue<int> one;
    rep(i, n) {
        if (s[i] == '1') one.push(i);
    }
    ll ans = 0; // int だと桁が足りない
                // e.g. s = 0...01...1 (0が250000, 1が250000), t = 1...10...0 (1が250000, 0が250000)
                // のとき答えは 250000^2 > 2^31
    rep(i, n) {
        if (s[i] == t[i]) continue;
        while (!one.empty() && i >= one.front()) {
            one.pop();
        }
        if (!one.empty()) {
            int j = one.front();
            one.pop();
            ans += j - i;
            s[j] = '0';
        } else {
            puts("-1");
            return;
        }
    }
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}

#include <bits/stdc++.h>

#define ll long long
#define ve vector<ll>
#define w(t) ll t; cin >> t; while(t--)

using namespace std;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int a, b, c;
    cin >> a >> b >> c;

    if (a == b)
        cout << c;
    else if (a == c)
        cout << b;
    else if (c == b)
        cout << a;
    else
        cout << 0;


    return 0;
}