#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 5e5+5;
const int INF = 0x3f3f3f3f;

int a[N],b[N];

inline int check1(int n){
	int A0 = 0,B0 = 0;
	vector <int> s,t;
	for(int i = 1;i <= n;++i){
		if(a[i] == 0) A0++,s.push_back(i);
		if(b[i] == 0) B0++,t.push_back(i);
	}
	if(A0 != B0) return INF;
	
	int res = 0;
	for(int i = 0;i < s.size();++i){
		if(s[i] == t[i]) res++;
	}
	return A0-res;
}

inline int check2(int n){
	int A0 = 0,B0 = 0;
	vector <int> s,t;
	for(int i = n;i;--i){
		if(a[i] == 0) A0++,s.push_back(i);
		if(b[i] == 0) B0++,t.push_back(i);
	}
	if(A0 != B0) return INF;
	
	int res = 0;
	for(int i = 0;i < s.size();++i){
		if(s[i] == t[i]) res++;
	}
	return A0-res;
}

int main() {
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;++i) scanf("%1d",&a[i]);
	for(int i = 1;i <= n;++i) scanf("%1d",&b[i]);
	
	int ans = INF;
	ans = min(ans,check1(n));
	ans = min(ans,check2(n));
	printf("%d\n",ans == INF ?-1 :ans);
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x) cerr << "[" << #x << "]: " << x << "\n";

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;

ld const PI = 4*atan((ld)1);
const int MAX = 5e5 + 69;

int main()
{
	fastio;

	int n;
	char s[MAX], t[MAX];

	cin >> n;
	cin >> s;
	cin >> t;

	int a = 0, b = 0;
	for (int i = 0; i < n; ++i)
		a += s[i] == '0', b += t[i] == '0';

	if (a != b)
	{
		cout << -1 << '\n';
		return 0;
	}

	vector<int> A, B;
	for (int i = 0; i < n; ++i)
	{
		if (s[i] == '0') A.pb(i);
		if (t[i] == '0') B.pb(i);
	}

	int res = 0;
	for (int i = 0; i < (int)A.size(); ++i)
	{
		if (A[i] == B[i])
			continue;
		res++;
	}

	cout << res << '\n';

	return 0;
}
