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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;

ld const PI = 4*atan((ld)1);

int const N = 5e5 + 7;

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

int main()
{
	fastio;

	cin >> n >> s >> t;

	int s_1 = 0;
	int t_1 = 0;
	for (int i = 0; i < n; ++i)
		s_1 += s[i] == '1';
	for (int i = 0; i < n; ++i)
		t_1 += t[i] == '1';

	if (s_1 < t_1 || (s_1 - t_1) % 2 == 1)
	{
		cout << -1 << '\n';
		return 0;
	}

	queue<int> q;
	for (int i = 0; i < n; ++i)
	{
		if (s[i] == '1')
			q.push(i);
	}

	ll res = 0;
	for (int i = 0; i < n; ++i)
	{
		if (t[i] == '0')
		{
			if (!q.empty() && i >= q.front())
			{
				int tmp = q.front();
				q.pop();

				if (q.empty())
				{
					cout << -1 << '\n';
					return 0;
				}

				res += q.front() - tmp;
				q.pop();
			}
		}
		else
		{
			if (q.empty())
			{
				cout << -1 << '\n';
				return 0;
			}

			res += q.front() - i;
			q.pop();
		}
	}
	cout << res << '\n';

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int N=5e5+1;
int n;
int a[N],b[N];
deque<int>p,q;
int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	int z=0;
	for(int i=1; i<=n ;i++){
		char c;cin >> c;
		if(c=='1') p.push_back(i);
	}
	for(int i=1; i<=n ;i++){
		char c;cin >> c;
		if(c=='1') q.push_back(i);
	}
	if(p.size()%2!=q.size()%2) return cout << "-1\n",0;
	ll ans=0;
	while(!q.empty()){
		if(p.front()<q.front()){
			if(p.size()>=2){
				int x=p.front();
				p.pop_front();
				int y=p.front();
				p.pop_front();
				ans+=y-x;
			}
			else return cout << "-1\n",0;
		}
		else{
			if(p.empty()) return cout << "-1\n",0;
			ans+=p.front()-q.front();
			p.pop_front();q.pop_front();
		}
	}
	while(!p.empty()){
		int x=p.front();
		p.pop_front();
		int y=p.front();
		p.pop_front();
		ans+=y-x;
	}
	cout << ans << '\n';
}