#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
long long maxSubArraySum(long long sym) {
  long long max_so_far = INT_MIN, max_ending_here = 0;
  for (long long i = 0; i < v.size(); i++) {
    max_ending_here = max_ending_here + sym * v[i];
    if (max_so_far < max_ending_here) max_so_far = max_ending_here;
    if (max_ending_here < 0) max_ending_here = 0;
  }
  return max_so_far;
}
int main() {
  long long n;
  cin >> n;
  string s1, s2;
  cin >> s1 >> s2;
  long long all_zero = 1, all_one = 1;
  for (long long i = 0; i < n; i++) {
    if (s1[i] == s2[i]) continue;
    if (s1[i] == '1') {
      v.push_back(1);
      all_zero = 0;
    } else {
      v.push_back(-1);
      all_one = 0;
    }
  }
  sort(s1.begin(), s1.end());
  sort(s2.begin(), s2.end());
  if (s1 == s2 && (all_one || all_zero))
    cout << 0 << '\n';
  else if (s1 == s2)
    cout << max(maxSubArraySum(1), maxSubArraySum(-1)) << '\n';
  else
    cout << -1 << '\n';
  return 0;
}
