#include <iostream>
using namespace std;

int main()
{
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  int ans = 0;
  int x = 0;
  for (int i = 0; i < n; i++) {
    int c = s[i] - '0' + (t[i] - '0') * 2;
    switch (c) {
    case 0:   x != 0 && ans++; break;
    case 1: ++x <= 0 && ans++; break;
    case 2: --x >= 0 && ans++; break;
    }
  }
  cout << (x == 0 ? ans : -1) << endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main()
{
    ll n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<ll> a, b;
    rep(i,n){
        if(s[i]=='0')a.emplace_back(i);
        if(t[i]=='0')b.emplace_back(i);
    }
    if(a.size() != b.size()){
        cout << -1 << endl;
    }else{
        ll ans = 0;
        rep(i,a.size()){
            if(a[i]!=b[i]) ans++;
        }
        cout << ans << endl;
    }
    
    return 0;
}