#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
template<typename T>void ckmn(T&a,T b){a=min(a,b);}
template<typename T>void ckmx(T&a,T b){a=max(a,b);}
void rd(int&x){scanf("%i",&x);}
void rd(ll&x){scanf("%lld",&x);}
void rd(char*x){scanf("%s",x);}
void rd(ldb&x){scanf("%lf",&x);}
void rd(string&x){scanf("%s",&x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&i:x)rd(i);}
template<typename T,typename...A>void rd(T&x,A&...args){rd(x);rd(args...);}
template<typename T>void rd(){T x;rd(x);return x;}
int ri(){int x;rd(x);return x;}
template<typename T>vector<T> rv(int n){vector<T> x(n);rd(x);return x;}
template<typename T>void ra(T a[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]);}
template<typename T1,typename T2>void ra(T1 a[],T2 b[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]);}
template<typename T1,typename T2,typename T3>void ra(T1 a[],T2 b[],T3 c[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]),rd(c[st+i]);}
void re(vector<int> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){rd(u,v);E[u].pb(v);if(!dir)E[v].pb(u);}}
template<typename T>void re(vector<pair<int,T>> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){T w;rd(u,v,w);E[u].pb({v,w});if(!dir)E[v].pb({u,w});}}

const int N=500050;
char s[N],t[N];
queue<int> A,B;
int main(){
	int n=ri();
	rd(s+1);rd(t+1);
	for(int i=1;i<=n;i++){
		if(s[i]=='1')A.push(i);
		if(t[i]=='1')B.push(i);
	}
	ll ans=0;
	while(A.size()||B.size()){
		if(B.empty()){
			if(A.size()==1)return 0*printf("-1\n");
			int i=A.front();A.pop();
			int j=A.front();A.pop();
			ans+=j-i;
		}else{
			if(A.empty())return 0*printf("-1\n");
			if(A.front()<B.front()){
				if(A.size()==1)return 0*printf("-1\n");
				int i=A.front();A.pop();
				int j=A.front();A.pop();
				ans+=j-i;
			}else{
				int i=B.front();B.pop();
				int j=A.front();A.pop();
				ans+=j-i;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
int n,s[500005],t[500005],tops,topt;
long long ans;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        char tmp;
        scanf(" %c",&tmp);
        if(tmp=='1') s[++tops]=i;
    }
    for(int i=1;i<=n;i++)
    {
        char tmp;
        scanf(" %c",&tmp);
        if(tmp=='1') t[++topt]=i;
    }
    reverse(s+1,s+tops+1);
    reverse(t+1,t+topt+1);
    while(tops!=0 || topt!=0)
    {
        if(tops==0)
        {
            printf("-1\n");
            return 0;
        }
        if(topt==0)
        {
            while(tops!=0)
            {
                if(tops==1)
                {
                    printf("-1\n");
                    return 0;
                }
                ans+=s[tops-1]-s[tops];
                tops-=2;
            }
            break;
        }
        while(s[tops]<t[topt])
        {
            if(tops==1)
            {
                printf("-1\n");
                return 0;
            }
            ans+=s[tops-1]-s[tops];
            tops-=2;
        }
        ans+=s[tops]-t[topt];
        tops--;
        topt--;
    }
    printf("%lld\n",ans);
}