#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif
using namespace std;

//#define int long long
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef vector<vector<int>> graph;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define MOD 1000000007
#define MAXX 1.1529215e+18
#define _1 first
#define _2 second
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())

template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}
 
template<class t> using vc=vector<t>;

template<class T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

template<class T>
T extgcd(T a, T b, T &x, T &y) {
    T d = a;
    if (b == 0) {
      x = 1;
      y = 0;
    } else {
      d = extgcd(b, a%b, y, x);
      y -= (a/b)*x;
    }
    return d;
}

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p._1<<","<<p._2<<"}";
}
 
template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}
 
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}

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

  int N;
  string S, T;
  cin >> N >> S >> T;
  vector<ll> vs;
  vector<ll> vt;
  bool flag = true;
  ll ans = 0;
  rep(i, N) {
    if (S[i] == '1') {
      vs.pb(i);
    }
    if (T[i] == '1') {
      vt.pb(i);
    }
  }
  vt.pb(INF);
  ll s = 0;
  ll t = 0;
  while(s < vs.size()) {
    if (vs[s] < vt[t]) {
      if (s <= vs.size()-2) {
        ans -= vs[s];
        ans += vs[s+1];
        s+=2;
      } else {
        flag = false;
        break;
      }
    }
    else {
      ans += vs[s]-vt[t];
      s++;
      t++;
    }
    // cout << s << ' ' << t << ' ' << ans << endl;
  }
  if (t < vt.size()-1) {
    flag = false;
  }
  if (flag)
    cout << ans << endl;
  else {
    cout << -1 <<endl;
  }
}

#include <bits/stdc++.h>
using namespace std;

// #include <atcoder/all>
// using namespace atcoder;

#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;

std::string S;
std::string T;

void solve(long long N){
    ll ans = 0;
    queue<int> carry_start_index;
    rep(i, N) {
        if (S[i] == '1') {
            if (carry_start_index.size()) {
                ans += i - carry_start_index.front();
                carry_start_index.pop();
                S[i] = '0';
            }
        }
        if (S[i] != T[i]) {
            carry_start_index.push(i);
        }
    }
    if (carry_start_index.size()) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    std::cin >> S;
    std::cin >> T;
    // solve(N, S, T);
    solve(N);
    return 0;
}
