#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using PIL = pair<int,ll>;
using PLI = pair<ll,int>;
using PLL = pair<ll,ll>;
using Graph = vector<vector<int>>;
using Cost_Graph = vector<vector<PIL>>;

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;}
template<class T> void show_vec(T v) {for (int i=0;i<v.size();i++) cout<<v[i]<<endl;}
template<class T> void show_pair(T p) {cout<<p.first<<" "<<p.second<<endl;}
template<class T> bool judge_digit(T bit,T i) {return (((bit&(1LL<<i))!=0)?1:0);}
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ROUNDUP(a,b) ((a+b-1)/b)
#define YESNO(T) cout<<(T?"YES":"NO")<<endl
#define yesno(T) cout<<(T?"yes":"no")<<endl
#define YesNo(T) cout<<(T?"Yes":"No")<<endl

const int INFint = 1 << 29;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007LL;
const double pi = 3.14159265358979;
const vector<int> h_idx4 = {-1, 0,0,1};
const vector<int> w_idx4 = { 0,-1,1,0};
const vector<int> h_idx8 = {-1,-1,-1, 0,0, 1,1,1};
const vector<int> w_idx8 = {-1, 0, 1,-1,1,-1,0,1};

int n;
string s,t;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    cin >> n >> s >> t;

    int s0 = 0,s1 = 0,t0 = 0,t1 = 0;
    for (int i = 0; i < n; i++){
        if (s[i] == '0') s0++;
        else s1++;

        if (t[i] == '0') t0++;
        else t1++;
    }

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

    vector<ll> ss,tt;
    for (int i = 0; i < n; i++){
        if (s[i] == '0') ss.push_back(i);
        if (t[i] == '0') tt.push_back(i);
    }

    int m = ss.size();
    int ans = 0;
    for (int i = 0; i < m; i++){
        if (ss[i] != tt[i]) ans++; 
    }

    cout << ans << endl;

}
#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<endl
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1e18+7;
const lint inf=1e9+7;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  string s;cin>>s;
  string t;cin>>t;
  lint res=0;
  vector<int> a,b;
  a.push_back(-1);
  b.push_back(-1);
  rep(i,n){
    if(s[i]=='1')a.push_back(i);
    if(t[i]=='1')b.push_back(i);
  }
  if(a.size()!=b.size()){
    cout<<-1<<"\n";
    return 0;
  }
  rep1(i,a.size()-1){
    int move=b[i-1]-a[i-1];
    int sub=b[i]-a[i];
    if(move<=0){
      if(b[i]<=a[i-1])res+=a[i]-a[i-1]-1;
      else res+=abs(sub);
    }
    else if(move>0){
      if(b[i-1]>=a[i])res+=b[i]-(b[i-1]+1);
      else res+=abs(sub);
    }
  }
  cout<<res<<"\n";
  return 0;
}