#include <bits/stdc++.h>
using namespace std;

template<typename T, typename U>
using vp = vector<pair<T,U>>;
template<typename T>
using pque = priority_queue<T>;
template<typename T>
using lpque = priority_queue<T,vector<T>,greater<T>>;

using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using vint = vector<int>;
using vll = vector<ll>;
using qint = queue<int>;
using pqint = pque<int>;
using qll = queue<ll>;
using pqll = pque<ll>;

constexpr double PI = 3.141592653589793;
constexpr int INTINF = (1<<30)-1;
constexpr ll LLINF = (1LL<<62)-1;
constexpr int MPRIME = 1000000007;
constexpr int MPRIME9 = 998244353;
constexpr ll MMPRIME = (1LL<<61)-1;
constexpr char newl = '\n';

#define len length()
#define pushb push_back
#define fi first
#define se second

#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

template<typename T>
struct matrix{
private:
	vector<vector<T>> mat;

public:
	matrix() : matrix(0,0) {}
	matrix(int h, int w) { resize(h,w); }
	matrix(int h, int w, T init) { resize(h,w,init); }

	void resize(int h, int w) {
		mat=vector<vector<T>>(h,vector<T>(w));
	}
	void resize(int h, int w, T init) {
		mat=vector<vector<T>>(h,vector<T>(w,init));
	};

	void in() {
		for(int i=0; i<mat.size(); i++) for(int j=0; j<mat[i].size(); j++) {
			cin>>mat[i][j];
		}
	}

	void out() {
		for(int i=0; i<mat.size(); i++) {
			int wm=mat[i].size();
			for(int j=0; j<wm; j++) {
				cout<<mat[i][j]<<(wm==j+1 ? '\n' : ' ');
			}
		}
		cout<<flush;
	}

	inline vector<T> &operator[](int idx) {
		assert(0<=idx && idx<mat.size());
		return mat[idx];
	}
};

template<class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

template<class T>
inline void out(T a) {
	cout<<a<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

long long binpow(long long a, long long ex, long long p=MMPRIME) {
	long long res = 1;
	while(ex > 0) {
		if(ex & 1) (res*=a) %= p;
		ex>>=1;
		(a*=a) %= p;
	}
	return res;
}


int N;
string S,T;

void input() {
	cin>>N>>S>>T;
}

void solve() {
	ll ans=0;
	for(int i=0, j=0; i<N; i++) {
		if(S[i]==T[i]) continue;
		if(S[i]=='1') {
			for(chmax(j,i+1); j<N; j++) {
				if(S[j]=='0') continue;
				S[i]=S[j]='0';
				ans += j-i;
				break;
			}
		}
		else {
			for(chmax(j,i+1); j<N; j++) {
				if(S[j]=='0') continue;
				S[i]='1';
				S[j]='0';
				ans += j-i;
				break;
			}
		}
	}
	if(S!=T) cout<<-1<<newl;
	else cout<<ans<<newl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t--) {
		input();
		solve();
	}
}

#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define ll long long
#define pb push_back
#define mem(x, y) memset(& x, y, sizeof(x))

const int n0 = 5e5 + 123;
int n;
ll p[n0];
string s, t;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> s >> t;
	vector <int> v, u;
	for (int i = 0; i < n; i++) {
		if (s[i] == '1') v.pb(i);
		if (t[i] == '1') u.pb(i);
	}
	if (SZ(v) < SZ(u) || (SZ(v) & 1) != (SZ(u) & 1)) return cout << -1, 0;
	ll res = 0;
	int last = -1;
	for (int i = 1; i <= SZ(v); i++) {
		p[i] = p[i - 1];
		if (i & 1) p[i] -= v[i - 1];
		else p[i] += v[i - 1];
	}
	for (int i = 0; i < SZ(u); i++) {
		int pos = lower_bound(begin(v) + (last + 1), end(v), u[i]) - begin(v);
		if (pos == SZ(v)) return cout << -1, 0;
		int x = pos - last - 1;
		if (x & 1) pos++;
		if (pos == SZ(v)) return cout << -1, 0;
		ll cur = p[pos] - p[last + 1];
		if ((last + 2) % 2 == 0) cur *= -1;
		res += v[pos] - u[i] + cur;
		last = pos;
	}
	int x = SZ(v) - last - 1;
	if (x & 1) return cout << -1, 0;
	ll cur = p[SZ(v)] - p[last + 1];
	if ((last + 2) % 2 == 0) cur *= -1;
	res += cur;
	cout << res;
}
