#include <bits/stdc++.h>
using namespace std;
long long n, a[1000005];
string s, t;
long long max_sum_subarray(long long x) {
  long long cur = 0, ret = 0;
  for (long long i = 0; i < n; i++) {
    cur += x * a[i];
    ret = max(ret, cur);
    if (cur < 0) cur = 0;
  }
  return ret;
}
void solve() {
  cin >> n >> s >> t;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] != t[i]) {
      if (s[i] == '1')
        a[i] = 1;
      else
        a[i] = -1;
    }
    sum += a[i];
  }
  if (sum) {
    cout << -1 << endl;
    return;
  }
  long long ans = max(max_sum_subarray(1), max_sum_subarray(-1));
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tt;
  tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
