#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int N;
string S, T;

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> S >> T;

    ll ans = 0;

    int pneed = 0;
    int par = (S[0] - '0') ^ (T[0] - '0');
    for (int i = 1; i < N; i++)
    {
        int ds = S[i] - '0', dt = T[i] - '0';

        int nneed;
        if (S[i-1] == '0')
            nneed = pneed;
        else
            nneed = max (0, pneed - 1);
        while (nneed % 2 != par) nneed++;
        ans += nneed;
        pneed = nneed;

        par ^= (ds ^ dt);
    }
    if (par || pneed > (S[N-1] - '0')) cout << "-1\n";
    else cout << ans << "\n";
}
#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define repd(z, x, y) for(int z=x;z>=y;--z)
#define com bool operator<(const node &b)const
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int maxn = (ll) 5e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int T = 1;
char s[maxn], t[maxn];

void solve() {
    int n;
    queue<int> q;
    cin >> n >> (s + 1) >> (t + 1);
    rep(i, 1, n)if (s[i] == '1')q.push(i);
    int ans = 0;
    rep(i, 1, n) {
        if (s[i] != t[i]) {
            while (!q.empty() && q.front() <= i)q.pop();
            if (q.empty()) {
                cout << -1;
                return;
            }
            s[q.front()] = '0';
            ans += q.front() - i;
            q.pop();
        }
    }
    cout << ans;
}

signed main() {
    start;
    while (T--)
        solve();
    return 0;
}