#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T> 
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}

/*
step0 A<BとかA%2!=B%2を除外
step1 自分より右が存在するかチェック
step2 残り物の消去
step3 マッチングしてく

*/

int main(){
    ll n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    ll A = 0;
    ll B = 0;
    ll ans = 0;//答え
    //step0
    rep(i,n){
        if(s[i]=='1')A++;
        if(t[i]=='1')B++;
    }
    if(A<B||A%2!=B%2){
        cout << -1 << endl;
        return 0;
    }

    ll a = 0;
    ll b = 0;
    //step1
    rep(i,n){
        if(A<B){
            cout << -1 << endl;
            return 0;
        }
        if(s[i]=='1')a++;
        if(t[i]=='1')b++;
        if(a>b){
            a--;
            s[i]='0';
            for(int j=i+1;j<n;j++){
                if(s[j]=='1'){
                    s[j]='0';
                    ans += j-i;
                    break;
                }
            }
            A -= 2;
        }
    }

    //step2
    ll dif = B-A;
    ll r = n;
    ll l = n;
    for(int i=n-1;i>=0;i--){
        if(dif==0)break;
        if(s[i]=='1'){
            if(dif%2==0){
                r = i;
                dif--;
            }
            else{
                ans += r-i;
                dif--;
            }
        }

    }

    //step3
    rep(i,n){
        if(s[i]=='1'){
            ans += i;
        }
        if(t[i]=='1'){
            ans -= i;
        }
    }
    cout << ans << endl;


    return 0;
}

// clang-format off
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcountll
#define ffs __builtin_ffsll
#define ctz __builtin_ctzll
#define clz __builtin_clz
#define clzll __builtin_clzll
#define all(a) (a).begin(), (a).end()

using namespace std;
using namespace __gnu_pbds;


using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
// clang-format on

int main() {
    fastio();

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

    int borrow = 0;
    ll ans = 0;
    forn(i, n) {
        ans += borrow;

        if (s[i] == '1' and t[i] == '0') {
            if (borrow > 0)
                borrow--;
            else
                borrow++;
        }

        if (s[i] == '0' and t[i] == '1') {
            borrow++;
        }
    }

    bool ok = borrow == 0;

    cout << (ok ? ans : -1) << endl;

    return 0;
}