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

const int N = 500003;

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

int main()
{
    scanf("%d%s%s",&n,s+1,t+1);
    long long sum = 0ll;
    int p=2;
    while(p<=n && s[p]!='1') ++p;
    for(int i=1;i<=n;++i) {
        if(p==i) {
            ++p;
            while(p<=n && s[p]!='1') ++p;
        }
        if(s[i]!=t[i] && p>n) {
            puts("-1");
            return 0;
        }
        if(s[i]=='0' && t[i]=='1') {
            swap(s[i],s[p]);
            sum += (p-i);
            while(p<=n && s[p]!='1') ++p;
        } else if(s[i]=='1' && t[i]=='0') {
            s[i] = s[p] = '0';
            sum += (p-i);
            while(p<=n && s[p]!='1') ++p;
        }
    }
    cout << sum;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

char S[500005];
char T[500005];

priority_queue<int, vector<int>, greater<int> > A;
vector<int> B;

int main(){
    int N;
    scanf("%d", &N);

    scanf(" %s %s", S, T);

    int sizeA = 0;
    for(int i = 0; i < N; i ++){
        if(S[i] == '1'){
            A.push(i);
            sizeA ++;
        }
        if(T[i] == '1'){
            B.push_back(i);
        }
    }

    if(sizeA < (int)B.size()){
        printf("-1");
        return 0;
    }else if( (sizeA-(int)B.size())&1 ){
        printf("-1");
        return 0;
    }

    //long long ans = (sizeA-(int)B.size())>>1;
    long long ans = 0;
    bool boleh = true;
    for(int i = 0; i < (int)B.size(); i ++){
        bool found = false;
        while(!A.empty()){
            int x = A.top();
            if(x >= B[i]){
                ans += x-B[i];
                A.pop();
                //printf("found x=%d B[i]=%d\n", x, B[i]);
                found = true;
                break;
            }else{
                A.pop();
                if(A.empty()){
                    printf("-1");
                    return 0;
                }
                int y = A.top();
                A.pop();
                //printf("found x=%d y=%d\n", x, y);
                ans += y-x;
            }
        }

        if(!found){
            boleh = false;
            break;
        }
    }

    while(!A.empty()){
        int x = A.top();
        A.pop();
        if(A.empty()){
            printf("-1");
            return 0;
        }
        int y = A.top();
        A.pop();
        //printf("lastly, found x=%d y=%d\n", x, y);
        ans += y-x;
    }

    if(!boleh){
        printf("-1");
        return 0;
    }
    printf("%lld", ans);
    return 0;
}

