#include <bits/stdc++.h>
using namespace std;
const int Max = 1e6 + 10;
const int Mod = 1e9 + 7;
const double PI = 3.141592653589793238463;
long long n, cum[Max + 10];
long long cal(long long m) {
  long long ans = 0, i;
  for (i = 1; i <= n; i++) ans += min(cum[i] % m, m - (cum[i] % m));
  return ans;
}
int main() {
  (ios_base::sync_with_stdio(false), cin.tie(NULL));
  ;
  long long i, j, m, p, a, sum = 0, k, t, b, c, d, cnt = 0, q, l, r;
  string str, ptr;
  bool flag = true;
  cin >> n;
  cin >> str >> ptr;
  a = 0, b = 0;
  vector<long long> v;
  long long o = 0, z = 0;
  long long ans = 0;
  for (i = 0; i < n; i++) {
    a += (str[i] == '1');
    b += (ptr[i] == '1');
    if (str[i] == ptr[i]) continue;
    if (str[i] == '0' && ptr[i] == '1')
      z++, o--;
    else {
      o++;
      z--;
    }
    z = max(z, 0ll);
    o = max(o, 0ll);
    ans = max(ans, abs(z - o));
  }
  if (a == b) {
    cout << ans << endl;
  } else
    cout << -1 << endl;
}
