#include <stdio.h>
#include <stack>
typedef long long ll;

int main(void) {
  ll i, j, k, n, ans = 0;
  scanf("%lld", &n);
  char s[n + 10], t[n + 10];
  scanf("%s%s", s, t);
  std::stack<ll> a, b;
  for(i = 0; i < n; ++i) {
    if(t[i] == '1') a.push(i);
    if(s[i] == '1') {
      if(b.size()) ans += i - b.top(), b.pop();
      else if(a.size()) ans += i - a.top(), a.pop();
      else b.push(i);
    }
  }
  printf("%lld", a.size() || b.size() ? -1 : ans);
  return 0;
}
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;

template<class T> bool chmin(T &a, T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b){a=b;return 1;}return 0;}
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;



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

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

    ll ssum = 0,tsum = 0;
    for (ll i = 0; i < n; i++){
        if (s[i] == '1'){
            ssum++;
        }

        if (t[i] == '1'){
            tsum++;
        }
    }

    if (ssum %2 != tsum %2){
        cout << -1 << endl;
        return 0;
    }

    ll erase = 0;
    ll ans = 0;
    ll count = 0;

    ll j = 0;

    for (ll i = 0; i < n; i++){
        if (t[i] == '0') continue;

        ll k = -1;

        while (j < i){
            if (s[j] == '1'){
                count++;
                if (count %2 == 1){
                    k = j;
                }
                else{
                    ans += (j - k);
                    k = -1;
                }
            }

            j++;
        }

        //cout << i << " " << j << " " << k << endl;

        if (k != -1){
            while (j < n){
                if (s[j] == '1'){
                    ans += (j - k);
                    //cout << ans << endl;
                    j++; count++;
                    k = -1;
                    break;
                }
                else j++;
            }
        }

        if (k != -1){
            cout << -1 << endl;
            return 0;
        }

        while (j < n){
            if (s[j] == '1'){
                ans += (j - i);
                //cout << ans << endl;
                break;
            }
            else j++;
        }

        if (j >= n){
            cout << -1 << endl;
            return 0;
        }
        else if (j == n-1){
            if (count != ssum - tsum){
                cout << -1 << endl;
                return 0;
            }
            else break;
        }
        else{
            j++;
        }

        //cout << ans << endl;
    }
    //cout << count << endl;

    if (count != ssum - tsum){
        //cout << "Yes" << endl;
        ll k = -1;
        for (ll i = n-1; i >= 0; i--){
            if (s[i] == '1'){
                count++;
                if (count %2 == 1){
                    k = i;
                }
                else{
                    ans += (k - i);
                    k = -1;
                }

                if (count == ssum - tsum) break;
            }
        }
    }

    cout << ans << endl;

}