#include <bits/stdc++.h>
using namespace std;
long long N = 1e6 + 15;
vector<long long> A(N, 0);
long long n;
long long kadane(long long x) {
  long long maxi = 0, cur = 0;
  for (long long i = 0; i < n; i++) {
    cur += x * A[i];
    maxi = max(maxi, cur);
    if (cur < 0) cur = 0;
  }
  return maxi;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  string s, t;
  cin >> s >> t;
  long long s0 = 0, s1 = 0, t0 = 0, t1 = 0;
  string str = "";
  for (long long i = 0; i < n; i++) {
    if (s[i] != t[i]) {
      if (s[i] == '1')
        A[i] = -1;
      else
        A[i] = 1;
      str += s[i];
    }
    if (s[i] == '0') s0++;
    if (s[i] == '1') s1++;
    if (t[i] == '0') t0++;
    if (t[i] == '1') t1++;
  }
  if (t0 != s0)
    cout << -1;
  else {
    cout << max(kadane(1), kadane(-1));
  }
  return 0;
}
