#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline long long add(long long a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
inline long long sub(long long a, long long b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
inline long long mul(long long a, long long b) {
  return (long long)((long long)a * b % mod);
}
long long n;
vector<long long> a;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  while (t--) {
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    vector<long long> v(2 * n + 1, 0);
    long long c1 = 0, c2 = 0;
    for (long long i = (1); i <= (n); i++) {
      if (s1[i - 1] != s2[i - 1]) {
        s1[i - 1] == '1' ? v[i] = 1 : v[i] = -1;
        s1[i - 1] == '1' ? c1++ : c2++;
      }
    }
    for (long long i = (n + 1); i <= (2 * n); i++) {
      v[i] = v[i - n];
    }
    long long l = 0;
    long long ans = 0;
    for (long long i = (1); i <= (2 * n); i++) {
      l = max(l + v[i], (long long)0);
      ans = max(l, ans);
    }
    if (c1 != c2)
      cout << -1;
    else
      cout << ans;
  }
  return 0;
}
