#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  long long int r, i;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long int power(long long int x, long long int y, long long int mod) {
  long long int temp, ty, my;
  if (y == 0) return 1;
  temp = power(x, y / 2, mod);
  ty = (temp % mod) * (temp % mod);
  if (y % 2 == 0) {
    return ty % mod;
  } else {
    my = (x % mod) * (ty % mod);
    return my % mod;
  }
}
void fastscan(int &number) {
  bool negative = false;
  register int c;
  number = 0;
  c = getchar();
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48;
  if (negative) number *= -1;
}
const long long int N = 2000010;
vector<long long int> graph[N];
long long int ar[N];
long long int br[N];
long long int visit[N];
double eps = 2.22045e-010;
long long int dpf[N];
long long int dpb[N];
long long int solve(long long int arr[], long long int n) {
  long long int i, j, k;
  long long int mx = 0;
  long long int temp = 0;
  for (i = (0); i < (n); i++) {
    temp += arr[i];
    temp = max(temp, 0LL);
    mx = max(mx, temp);
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m, i, t, j, k, q;
  long long int a, b, c, h, d;
  cin >> n;
  string a1, a2;
  cin >> a1;
  cin >> a2;
  long long int c1 = 0, c2 = 0;
  for (i = (0); i < (n); i++) {
    if (a1[i] == a2[i]) {
      ar[i] = 0;
      br[i] = 0;
    } else if (a1[i] == '1') {
      ar[i] = 1;
      br[i] = -1;
      c1++;
    } else {
      ar[i] = -1;
      br[i] = 1;
      c2++;
    }
  }
  if (c1 != c2) {
    cout << "-1\n";
    return 0;
  }
  long long int ans = max(solve(ar, n), solve(br, n));
  cout << ans << "\n";
  return 0;
}
