/**
 *    author:  tourist
 *    created: 15.12.2020 16:15:36       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  string t;
  cin >> s;
  cin >> t;
  vector<int> p;
  int ptr = 0;
  int last = -1;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (t[i] == '1') {
      p.push_back(i);
    }
    if (s[i] == '1') {
      if (last != -1) {
        ans += i - last;
        last = -1;
      } else {
        if (ptr < (int) p.size()) {
          ans += i - p[ptr++];
        } else {
          last = i;
        }
      }
    }
  }
  if (last != -1 || ptr < (int) p.size()) {
    ans = -1;
  }
  cout << ans << '\n';
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> X(n), Y(n);
  rep(i, n) cin >> X[i] >> Y[i];
  int ans = 0;
  rep(i, n) REP(j, i+1, n) {
    if(-abs(X[j]-X[i]) <= (Y[j]-Y[i]) && (Y[j]-Y[i]) <= abs(X[j]-X[i])) ans++;
  }
  cout << ans << endk;
  return 0;
}
