#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 500000
#define LL long long
using namespace std;
int n,nxt1[N+5],nxt2[N+5];char s1[N+5],s2[N+5];
int main()
{
	RI i,j;LL t=0;scanf("%d%s%s",&n,s1+1,s2+1);
	for(j=0,i=1;i<=n;++i) s1[i]&1&&(nxt1[j]=i,j=i);nxt1[j]=n+1;
	for(j=0,i=1;i<=n;++i) s2[i]&1&&(nxt2[j]=i,j=i);nxt2[j]=n+1;
	#define NA() return puts("-1"),0;
	i=0,j=0;W(i<=n) if(i>=j) t+=i-j,i=nxt1[i],j=nxt2[j];
		else if(nxt1[i]<=n) t+=nxt1[i]-i,i=nxt1[nxt1[i]];else NA();
	return j>n?printf("%lld\n",t):puts("-1"),0;
}
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<pll,pll> ppp;
typedef vector<ll> vll;
typedef vector<pll> vp;
typedef priority_queue<pll,vp,greater<pll> > pqpll;
typedef priority_queue<ll, vll, greater<ll> > pqll;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second
#define EPS 1e-10
#define ALL(a) (a.begin(), a.end())

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T> > &pq) {return (ll)pq.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>, greater<T> > &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); } 
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

int main(){
    ll n;
    cin >> n;
    string s,t;
    cin >> s >> t;

    vll sum(n+1,0),sum2(n+1,0);
    ll lsb = 0;

    rep(i,0,n){
        if(s[i] == '1') sum[i+1] = 1;
        else sum[i+1] = 0;

        if(t[i] == '1') {
            sum2[i+1] = 1;
            if(lsb == 0) lsb = i+1;
        }
        else sum2[i+1] = 0;

        if(i != 0){
            sum[i+1] += sum[i];
            sum2[i+1] += sum2[i];
        }
    }

    if(sum[n] - sum[max(lsb-1,0ll)] < sum2[n]){
        cout << -1 << endl;
        return 0;
    }
    if((sum[max(lsb-1,0ll)] + (sum[n] - sum[max(lsb-1,0ll)] - sum2[n])) % 2 == 1){
        cout << -1 << endl;
        return 0;
    }

    stack<ll> sta1,sta2;
    ll ans = 0;

    rep(i,0,n){
        if(t[i] == '1'){
            sta2.push(i);
        }

        if(s[i] == '1'){
            if(sta1.size() > 0){
                ans += i - sta1.top();
                sta1.pop();
            }
            else if(i+1 < lsb){
                sta1.push(i);
            }
            else if(sta2.size() > 0){
                ans += i - sta2.top();
                sta2.pop();
            }
            else{
                sta1.push(i);
            }
        }
    }

    if(sta1.size() + sta2.size() == 0) cout << ans << endl;
    else cout << -1 << endl;
}


