#include <bits/stdc++.h>
#define pb push_back
#define vii vector<int>
#define task "poetry"
#define pll pair<ll, ll>
#define pii pair< ll, pair< ll, ll > >
#define fi first
#define se second

using namespace std;
using ll = long long;
using ull = unsigned long long;
const int N = 5e3+5;
const ll mod = 1e9+7;
const ll modx = 2019201913;
const ll mody = 2019201949;
ll m, n, k, T, u, v, tong, lab[N];
ll dp[N][N], a[N], d[N], c[N], b[N], ans, len[N];
string s, t ;
vector<ll> kq, adj[N], adt[N], res;

void dfs(ll u)
{
    kq.pb(u);
    a[u] = -1;
    for(ll v : adj[u])
    {
        if(a[v] == 0)dfs(v);
    }
}

void sol()
{
    /*
    cin >> n;
    for(int i = 0; i < n; i ++)cin >> s[i];
    for(int i = 0; i < n; i ++)
    {
        for(int j = 0; j < n; j ++)
        {
            if(s[i][j] == '1')
            {
                adj[i].pb(j);
                adt[j].pb(i);
            }
        }
    }
    for(int i = 0; i < n; i ++)if(a[i] == 0)dfs(i);
    for(int i = kq.size()-1; i >= 0; i --)
    {
        if(a[kq[i]] == 1)
        {
            ++k;
            bfs(kq[i], k);
        }
    }
    cout << k << '\n';
    for(ll u : res)cout << u <<" ";
    */
    queue<ll> ds;
    cin >> n >> s >> t;
    if(s[0] != t[0])
    {
        ds.push(1);
    }
    for(int i = 2; i <= n; i ++)
    {
        if(s[i-1] == '1')
        {
            if(!ds.empty())
            {
                k = ds.front();
                ds.pop();
                s[i-1] = '0';
                ans += i - k;
                k = 0;
            }
        }
        if(s[i-1] != t[i-1])ds.push(i);
    }
    if(!ds.empty())cout << -1;
    else cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen(task".in", "r"))
    {
		freopen(task".in","r",stdin);
		freopen(task".out","w",stdout);
    }
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
8 6 5
*/

#include<bits/stdc++.h>
using namespace std;
const int buffer_size=1e5+5;
char buf[buffer_size],*S,*T;
bool flag_EOF;
inline char read_char()
{
    if(S==T)
        T=(S=buf)+fread(buf,1,buffer_size,stdin);
    return S!=T?*(S++):EOF;
}
inline int read_int()
{
    int flag=1;
    char c=read_char();
    while(c<'0'||c>'9')
    {
        if(c==EOF)
        {
            flag_EOF=true;
            return 0;
        }
        flag=(c=='-'?-1:flag);
        c=read_char();
    }
    int x=0;
    while(c>='0'&&c<='9')
    {
        x=x*10+(c^48);
        c=read_char();
    }
    return x*flag;
}
inline void Write(int x)
{
    if(!x)
    {
        putchar('0');
        return;
    }
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    static char st[13];
    int head=0;
    while(x)
    {
        st[++head]=x%10+'0';
        x/=10;
    }
    while(head>0)
        putchar(st[head--]);
}
const int max_n=5e5+5;
char s[max_n],t[max_n];
int q[max_n],head=1,tail;
int main()
{
	int n;
	scanf("%d%s%s",&n,s+1,t+1);
	for(int i=1;i<=n;++i)
	{
		if(s[i]=='1')
			q[++tail]=i;
	}
	long long ans=0;
	for(int i=1;i<=n;++i)
	{
		if(head<=tail&&q[head]==i)
			++head;
		if(s[i]!=t[i])
		{
			if(head>tail)
			{
				printf("-1");
				return 0;
			}
			ans+=q[head]-i;
			s[q[head++]]='0';
		}
	}
	printf("%lld",ans);
	return 0;
}
