#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define printg(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif

#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int get_random() {
    static uniform_int_distribution<int> dist(0, 1e9 + 6);
    return dist(rng);
}
#define solve_testcase int T;cin>>T;for(int t=1;t<=T;t++){solve(t);}


typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type,op,val) bind(op<type>(), std::placeholders::_1, val)

template<class T>
void make_unique(T & v) {
    sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
}
int geti() { int x; cin >> x; return x; }
long long getll() { long long x; cin >> x; return x; }
double getd() { double x; cin >> x; return x; }
// pair<int, int> a(geti(), geti()) does not work
// pair<int, int> a({geti(), geti()}) works, since it uses initializer.

const int MAXN = 3e5 + 100;

void solve(int tt) {
    // cout<<"Case #"<<tt<<": ";
}

int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // solve_testcase;

    int n;
    cin>>n;
    string s,t;
    cin>>s;
    cin>>t;

    int cs=0,ct=0;
    for(auto c:s) cs+=(c=='1');
    for(auto c:t) ct+=(c=='1');

    print(cs,ct);

    if(cs<ct||(cs-ct)%2) {
    	cout<<-1<<endl;
    	return 0;
    }

    ll res=0;
    int i=0,j=0;

    while(1) {
	    for(;i<n&&s[i]=='0';i++);
	    for(;j<n&&t[j]=='0';j++);
    	print(i,j);
	    if(i==n&&j==n) break;
		if(i==n) {
			cout<<-1<<endl;
			return 0;
		}

    	if(i>=j) {
    		res+=i-j;
    		i++;j++;
    	}
    	else {
    		int i1=i+1;
		    for(;i1<n&&s[i1]=='0';i1++);
		    if(i1==n) {
		    	cout<<-1<<endl;
		    	return 0;
		    }
		    res+=i1-i;
			i=i1+1;
    	}
    }
    cout<<res<<endl;



    return 0;
}












#include <stdio.h>
#include <string.h>
#include <vector>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <functional>
#include <numeric>
const int MAXN = 500010;
char str_s[MAXN];
char str_t[MAXN];
std::vector<int> vec_index_s;
std::vector<int> vec_index_t;
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int t;
	int n, m, k, x;
	//scanf(" %d", &t);
	//while (t--) 
	{
		scanf("%d", &n);
		scanf(" %s", str_s);
		scanf(" %s", str_t);
		int cnt1 = 0;
		int cnt2 = 0;
		for (int i = 0; i < n; i++) {
			if (str_s[i] == '1') {
				cnt1++;
				vec_index_s.push_back(i);
			}
		}
		for (int i = 0; i < n; i++) {
			if (str_t[i] == '1') {
				cnt2++;
				vec_index_t.push_back(i);
			}
		}
		if (cnt2 > cnt1 || (cnt1 - cnt2) % 2) {
			printf("-1\n");
			return 0;
		}
		int index_now_s = 0;
		int index_now_t = 0;
		bool tag = true;
		long long res = 0;
		while (index_now_s < vec_index_s.size()) {
			if (index_now_t < vec_index_t.size() && vec_index_s[index_now_s] < vec_index_t[index_now_t]) {
				index_now_s++;
				if (index_now_s >= vec_index_s.size()) {
					break;
				}
				res += (vec_index_s[index_now_s] - vec_index_s[index_now_s - 1]);
				index_now_s++;
				if (index_now_s >= vec_index_s.size()) {
					break;
				}
			}
			else {
				if (index_now_t < vec_index_t.size()) {
					res += (vec_index_s[index_now_s] - vec_index_t[index_now_t]);
					index_now_s++;
					index_now_t++;
					if (index_now_s >= vec_index_s.size()) {
						break;
					}
				}
				else {
					index_now_s++;
					if (index_now_s >= vec_index_s.size()) {
						tag = false;
						break;
					}
					res += (vec_index_s[index_now_s] - vec_index_s[index_now_s - 1]);
					index_now_s++;
					if (index_now_s >= vec_index_s.size()) {
						break;
					}
				}
			}
		}
		if ((index_now_s >= vec_index_s.size() && index_now_t < vec_index_t.size()) || !tag) {
			printf("-1\n");
			return 0;
		}
		printf("%lld\n", res);
	}
	return 0;
}