#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <unordered_map>
#include <cstdio>
#include <climits>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n;
string s, t;
queue<int> que;
ll ans;

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> n >> s >> t;
	for (int i = 0; i < n; i++)if (s[i] == '1')que.push(i);
	for (int i = 0; i < n; i++) {
		if (!que.empty() && que.front() == i)que.pop();
		if (s[i] == t[i])continue;
		if (que.empty()) {
			cout << -1 << endl;
			return 0;
		}
		int p = que.front();
		ans += p - i;
		que.pop();
		if (s[i] == '0')s[i] = '1', s[i + 1] = '0', s[p] = '0';
		else s[i] = '0', s[i + 1] = '0', s[p] = '0';
	}
	cout << ans << endl;
}
#include<bits/stdc++.h>
using namespace std;

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

template<typename T> bool chmax(T &a,const T b){if(a < b){a=b; return true;} return false;}
template<typename T> bool chmin(T &a,const T b){if(a > b){a=b; return true;} return false;}


int N;
ll ans=0;
string S, T; 
vi cnt1(2, 0);

int solve(){
    queue<int> que1, que2;
    for(int i=0; i<N; i++){
        if(S[i] == '1') que1.push(i);
        if(T[i] == '1') que2.push(i);
    }
    while(!que1.empty() || !que2.empty()){
        if(que1.empty()) return 0;
        int a=que1.front(); que1.pop();
        if(!que2.empty()){
            int b=que2.front(); 
            if(a >= b){
                ans=ans+a-b;
                que2.pop();
            }
            else{
                if(que1.empty()) return 0;
                int c=que1.front(); que1.pop();
                ans=ans+c-a;
            }
        }
        else{
            if(que1.empty()) return 0;
                int c=que1.front(); que1.pop();
                ans=ans+c-a;
        }
    }
    return 1;
}

int main(){
    cin >> N;
    cin >> S >> T;

    if(solve()){
        cout << ans << endl;
    }
    else cout << "-1" << endl;
    return 0;
}