#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const ld eps = 1e-9;
const char newl = '\n';

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

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

  ll ss=0, tt=0, ans=0;
  ql q;
  rep(i, n) {
    if(t[i]=='1') q.push(i);

    if(s[i]=='1') {
      if(q.size()) {
        ans += i - q.front();
        q.pop();
      }else {
        ss = 1 - ss;
        q.push(i);
      }
    }
  }

  cout << (q.empty() ? ans : -1) << newl;
  return 0;
}
#include <iostream>
#include <cstdio>
#define maxn 500005
using namespace std;
int n, pos[maxn], cnt;
char s[maxn], t[maxn];
int main()
{
	scanf("%d%s%s", &n, s + 1, t + 1);
	for (int i = 1; i <= n; i++)
	{
		if(t[i] == '1') pos[++cnt] = i;
	}
	int now = 1, st = 0;
	long long ans = 0;
	for (int i = 1; i <= n; i++)
	{
		if(s[i] == '0') continue;
		if(st)
		{
			ans += i - st;
			st = 0;
		}
		else
		{
			if(i >= pos[now] && now <= cnt) 
			{
				ans += i - pos[now];
				now++;
			}
			else st = i;
		}
	}
	if(now <= cnt || st) printf("-1");
	else printf("%lld", ans);
	return 0;
}