#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
	int n; cin >> n;
	string t; cin >> t;
	string s = "110";
	long long res = 0;
	REP(i, 3) {
		bool ok = true;
		REP(j, n) ok = ok && s[(i+j)%3] == t[j];
		if (ok) res += 1e10 - (n+i+2)/3 + 1;
	}
	cout << res << '\n';
	return 0;
}

// #include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define BIT(n, k) ((n >> k) & 1)
#define LEN(s) (int)s.size()
#define RANGE(a) a.begin(), a.end()
#define RRANGE(a) a.rbegin(), a.rend()
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;

  deque<int> idx1;
  rep(i, n) if (s[i] == '1') idx1.push_back(i);

  ll ans = 0;
  rep(i, n) {
    if (s[i] == '1') idx1.pop_front();
    if (s[i] == t[i]) continue;
    if (s[i] == '1') {
      if (idx1.size() == 0) {
        ans = -1;
        break;
      }
      int j = idx1.front();
      ans += j - i;
      s[j] = '0';
      idx1.pop_front();

    } else if (s[i] == '0') {
      if (idx1.size() == 0) {
        ans = -1;
        break;
      }
      int j = idx1.front();
      ans += j - i;
      s[j] = '0';
      idx1.pop_front();
    }
  }
  cout << ans << endl;
}
