#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ll N;
    cin >> N;

    string S;
    cin >> S;
    queue<int> I;
    for (ll i = 0; i < N; ++i) {
        if (S[i] == '1') {
            I.emplace(i);
        }
    }

    string T;
    cin >> T;
    vector<int> E;
    for (ll i = 0; i < N; ++i) {
        if (T[i] == '1') {
            E.emplace_back(i);
        }
    }

    ll E_size = E.size();
    ll I_size = I.size();
    if ((E_size - I_size) % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0;
    ll I_first;
    ll I_second;
    for (auto E_num : E) {
        if (I.empty()) {
            cout << -1 << endl;
            return 0;
        }
        I_first = I.front();
        I.pop();
        while (I_first < E_num) {
            if (I.empty()) {
                cout << -1 << endl;
                return 0;
            }
            I_second = I.front();
            I.pop();
            ans += I_second - I_first;

            if (I.empty()) {
                cout << -1 << endl;
                return 0;
            }
            I_first = I.front();
            I.pop();
        }
        ans += I_first - E_num;
    }

    while (!I.empty()) {
        I_first = I.front();
        I.pop();
        I_second = I.front();
        I.pop();
        ans += I_second - I_first;
    }

    cout << ans << endl;
}
#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    string S, T; cin >> S >> T;
    //1101100011100
    //0100101010100
    queue<int> T_one;
    ll ans = 0;
    rep(i, N){
        //cout << i << endl;
        if(T[i] == '1') T_one.push(i);
        if(S[i] == '1' && T_one.empty()){
            int old_i = i;
            i++;
            while(i < N && S[i] == '0'){
                if(T[i] == '1') T_one.push(i);
                i++;
            }
            if(T[i] == '1') T_one.push(i);
            ans += i-old_i;
        }
        else if(S[i] == '1'){
            int aim = T_one.front();
            T_one.pop();
            ans += i-aim;
        }
    }
    if(T_one.empty()) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}