#include <bits/stdc++.h>

#define ln                 '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 5e5;
char s[nsz + 5], t[nsz + 5];
int n, ans;

int main() {
	scanf("%d", &n);
	scanf("%s", s);
	scanf("%s", t);
	int c0 = 0, c1 = 0;
	loop (i, n) {
		c0 += s[i] == '0';
		c1 += t[i] == '0';
	}
	if (c0 != c1) {
		printf("-1\n");
		return 0;
	}
	for (int i0 = 0, j0 = 0, i1 = 0, j1 = 0; i0 < n && i1 < n; i0 = j0 + 1, i1 = j1 + 1) {
		for (j0 = i0; j0 < n && s[j0] == '1'; ++j0);
		for (j1 = i1; j1 < n && t[j1] == '1'; ++j1);
		ans += j0 != j1;
	}
	printf("%d\n", ans);
}
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ud unsigned int
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x3f
#define MAX_INF_VAL 0x3f3f3f3f
#define MAX_INF_VAL_LL 0x3f3f3f3f3f3f3f3f
//#define pi 3.141592653589
#define eps 1e-9
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
//#define p 2173412051LL
//#define sz 2

using namespace std;

template< typename T > void read( T &x ) {
	x = 0;
	char ch = getchar();
	ll f = 1;
	while( !isdigit( ch ) ) {
		if( ch == '-' )
		f *= -1;
		ch = getchar();
	}
	while( isdigit( ch ) ) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	x *= f;
}

struct custom_hash {
    static uint64_t splitmix64( uint64_t x ) {
        x += 0x9e3779b97f4a7c15;
        x = ( x ^ ( x >> 30 ) ) * 0xbf58476d1ce4e5b9;
        x = ( x ^ ( x >> 27 ) ) * 0x94d049bb133111eb;
        return x ^ ( x >> 31 );
    }

    size_t operator() ( uint64_t x ) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64( x + FIXED_RANDOM );
    }
};

char s[ 500010 ], t[ 500010 ];
vector< int > a, b;

int main() {
	ios::sync_with_stdio( false );
	cin.tie( 0 ), cout.tie( 0 );
	int n;
	cin >> n;
	cin >> s + 1 >> t + 1;
	for( int i = 1; i <= n; ++i ) {
		if( s[ i ] == '0' )
			a.push_back( i );
		if( t[ i ] == '0' )
			b.push_back( i );
	}
	if( a.size() != b.size() ) {
		cout << "-1";
		return 0;
	}
	int ans = 0;
	for( int i = 0; i < a.size(); ++i ) {
		if( a[ i ] != b[ i ] )
			++ans;
	}
	cout << ans;
	return 0;
}