#include <iostream>
#include <vector>

using namespace std;

void solve() {
    int n;
    cin >> n;

    vector<int> xs, ys;
    for (int i = 0; i < n; ++i) {
        char c;
        cin >> c;
        if (c == '0') xs.push_back(i);
    }
    for (int i = 0; i < n; ++i) {
        char c;
        cin >> c;
        if (c == '0') ys.push_back(i);
    }

    if (xs.size() != ys.size()) {
        cout << "-1\n";
        return;
    }

    int ans = 0;
    for (int i = 0; i < (int)xs.size(); ++i) {
        if (xs[i] != ys[i]) ++ans;
    }

    cout << ans << "\n";
}

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

    solve();

    return 0;
}

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define all( v )        begin( v ), end( v )
#define rep( i, j )     for ( int i = 0; i < (int)j; ++i )
#define rep2( i, j, k ) for ( int i = j; i <= (int)k; ++i )
#define rep3( i, j, k ) for ( int i = j; i >= (int)k; --i )

template < class S, class T > inline bool chmax( S& x, T y ) {
  if ( x < y ) {
    x = y;
    return true;
  }
  return false;
}

template < class S, class T > inline bool chmin( S& x, T y ) {
  if ( x > y ) {
    x = y;
    return true;
  }
  return false;
}
template < class T > struct edge {
  int from, to;
  T cost;

  edge( int to = 0 ) : from( -1 ), to( to ), cost( 0 ) { };
  edge( int to, T cost ) : from( -1 ), to( to ), cost( cost ) { }
  edge( int from, int to, T cost ) : from( from ), to( to ), cost( cost ) { }

  edge& operator=( const int& x ) {
    to = x;
    return *this;
  }
};

template < class T > using pq    = priority_queue< T >;
template < class T > using pqg   = priority_queue< T, vector< T >, greater< T > >;
template < class T > using Edges = vector< edge< T > >;
template < class T > using Graph = vector< Edges< T > >;

using ld  = long double;
using ll  = long long;
using pi  = pair< int, int >;
using pl  = pair< ll, ll >;
using vi  = vector< int >;
using vl  = vector< ll >;
using vpi = vector< pi >;
using vpl = vector< pl >;
using vvi = vector< vi >;
using vvl = vector< vl >;

const ll INFLL = 100000000000000000;
const ll INF   = 1000000000;
const ll MAX   = 500005;
const ll MOD   = 1000000007;
// const ll MOD = 998244353;

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

  int n;
  cin >> n;

  string s, t;
  cin >> s >> t;

  ll x = count( all( s ), '0' ), y = count( all( t ), '0' );
  if ( x != y ) {
    cout << -1 << endl;
    return ( 0 );
  }

  ll ans = x;
  int a = 0, b = 0;

  rep( i, n ) {
    if ( s[i] == '0' ) ++a;
    if ( t[i] == '0' ) ++b;
    if ( s[i] == t[i] && s[i] == '0' && a == b ) --ans;
  }

  cout << ans << endl;

  return ( 0 );
}
