#include <bits/stdc++.h>
using namespace std;
/*
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
*/
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}
ll mod_pow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }

const int mod = 1e9 + 7;

int conv(string &S, string &T) {
    int ret = 0;
    int N = S.size();
    priority_queue<int, vector<int>, greater<int>> Q;
    for (int i = 0; i < N; i++) {
        if (T[i] == '0') {
            Q.push(i);
        }
    }
    for (int i = 0; i < N; i++) {
        if (T[i] == '1' && S[i] == '0') {
            while(!Q.empty()) {
                int x = Q.top(); Q.pop();
                if (x <= i) continue;
                swap(T[i], T[x]);
                ret++;
                break;
            }
        }
    }
    return ret;
}

int f(string &S, string &T) {
    string S_ = T, T_ = S;

    int r1 = conv(S, T);
    reverse(all(S));
    reverse(all(T));
    int r2 = conv(S, T);

    int r3 = conv(S_, T_);
    reverse(all(S_));
    reverse(all(T_));
    int r4 = conv(S_, T_);


    return min(r1 + r2, r3 + r4);
}

void solve() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    int s1 = 0, t1 = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '1') s1++;
    }
    for (int i = 0; i < N; i++) {
        if (T[i] == '1') t1++;
    }
    if (s1 != t1) {
        cout << "-1" << endl;
        return;
    }

    int prev = 0;
    s1 = 0, t1 = 0;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '1') s1++;
        if (T[i] == '1') t1++;
        if (s1 == t1) {
            string s = S.substr(prev, i + 1 - prev);
            string t = T.substr(prev, i + 1 - prev);
            ans += f(s, t);
            prev = i + 1;
        }
    }
    cout << ans << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}
#include <bits/stdc++.h>
using namespace std ;

int N, ans=0;
string S, T;
vector<int> a, b;

int main(){
  cin >> N >> S >> T;
  bool f=true;
  int x=-1;
  for(int i=0;i<N;i++){
    if(S[i]=='0')a.push_back(i);
    if(T[i]=='0')b.push_back(i);
  }
  if(a.size()!=b.size())puts("-1");
  else{
    for(int i=0;i<a.size();i++){
      if(a[i]!=b[i])ans++;
    }
    cout << ans << endl;
  }

  return 0;
}
