#include <bits/stdc++.h>
using namespace std;
long long const mod = 1e9 + 7;
long long const inf = 2e18;
inline long long add(long long a, long long b) {
  return (a % mod + b % mod + mod) % mod;
}
inline long long mul(long long a, long long b) {
  return (a % mod * b % mod + mod) % mod;
}
inline long long sub(long long a, long long b) {
  return (a % mod - b % mod + mod) % mod;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long modexp(long long x, long long n) {
  if (n == 0) {
    return 1;
  } else if (n & 1) {
    return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod;
  } else {
    return (modexp((x * x) % mod, n / 2) % mod);
  }
}
long long modinv(long long n) { return modexp(n, mod - 2); }
void solve() {
  long long n;
  cin >> n;
  string second, t;
  cin >> second >> t;
  set<long long> s1[2];
  for (long long i = 0; i < (n); i++) {
    if (second[i] != t[i]) {
      s1[t[i] - '0'].insert(i);
    }
  }
  if (s1[0].size() != s1[1].size()) {
    cout << "-1";
    return;
  }
  long long ans = 0;
  auto x = s1[0].begin();
  auto y = s1[1].begin();
  while (!s1[0].empty()) {
    x = s1[0].begin();
    y = s1[1].begin();
    long long last = -1;
    ans++;
    if (*x < *y) {
      while (1) {
        x = s1[0].lower_bound(last);
        y = s1[1].lower_bound(*x);
        if (x == s1[0].end() || y == s1[1].end()) break;
        last = *y;
        s1[0].erase(x);
        s1[1].erase(y);
      }
    } else {
      while (1) {
        y = s1[1].lower_bound(last);
        x = s1[0].lower_bound(*y);
        if (x == s1[0].end() || y == s1[1].end()) break;
        last = *x;
        s1[0].erase(x);
        s1[1].erase(y);
      }
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T = 1;
  for (int t = 1; t <= T; t++) {
    solve();
  }
  return 0;
}
