#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxm=2e6+5;
char s[maxm];
char t[maxm];
int n;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
    cin>>n;
    cin>>(s+1);
    cin>>(t+1);
    vector<int>pos;
    for(int i=1;i<=n;i++){
        s[i]-='0',t[i]-='0';
        if(s[i])pos.push_back(i);
    }
    int len=pos.size();
    int cur=0;
    int ans=0;
    for(int i=1;i<=n;i++){
        while(cur<len&&pos[cur]<=i)cur++;
        if(s[i]==t[i])continue;
        if(cur>=len){
            cout<<-1<<endl;
            return 0;
        }
        ans+=pos[cur]-i;
        s[pos[cur]]=0;
        cur++;
    }
    cout<<ans<<endl;
    return 0;
}
//ABC 182 C - To 3 
//题目地址：https://atcoder.jp/contests/abc182/tasks/abc182_c
 
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
 
int main() {
    int64_t n;
    scanf("%" SCNd64, &n);
 
    int cnt[3] = { 0 };
    while (n) {
        cnt[n % 10 % 3]++;
        n /= 10;
    }
    int cur = (cnt[1] + 2 * cnt[2]) % 3;
    int k = cnt[0] + cnt[1] + cnt[2];
    int res;
    if (!cur) res = 0;
    else if (cur == 1) {
        if (cnt[1]) {
            if (k == 1) res = -1;
            else res = 1;
        } else {
            if (k == 2) res = -1;
            else res = 2;
        }
    } else {
        if (cnt[2]) {
            if (k == 1) res = -1;
            else res = 1;
        } else {
            if (k == 2) res = -1;
            else res = 2;
        }
    }
    printf("%d\n", res);
 
    return 0;
}

 