#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = 0;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int mod = 1e9 + 7;
const int maxn = 1e6 + 100;
int T, n, m, q, k;
char ss[maxn << 1], tt[maxn << 1];
int main() {
  n = read();
  int nu1 = 0, nu2 = 0;
  scanf("%s", ss);
  scanf("%s", tt);
  for (int i = 0; i < n; i++) {
    if (ss[i] == '1') nu1++;
    if (tt[i] == '1') nu2++;
    ss[i + n] = ss[i];
    tt[i + n] = tt[i];
  }
  if (nu1 != nu2) {
    printf("-1\n");
    return 0;
  }
  int ans = 0, ji = 0, mx = 0, mn = 0;
  for (int i = 0; i < n * 2; i++) {
    if (ss[i] == '1' && tt[i] == '0')
      ji++;
    else if (ss[i] == '0' && tt[i] == '1')
      ji--;
    mx = max(mx, ji);
    mn = min(mn, ji);
  }
  cout << mx - mn << endl;
  return 0;
}
