#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  string s, t;
  int sz = 0, tz = 0;
  cin >> s >> t;
  for (long long int i = 0; i <= s.size() - 1; i++)
    if (s[i] == '0') sz++;
  for (long long int i = 0; i <= t.size() - 1; i++)
    if (t[i] == '0') tz++;
  if (sz != tz) {
    cout << -1 << "\n";
    return 0;
  }
  vector<long long int> sd;
  for (long long int i = 0; i <= s.size() - 1; i++)
    if (s[i] != t[i]) sd.push_back((s[i] == '0' ? -1 : 1));
  if (sd.empty()) {
    cout << 0 << "\n";
    return 0;
  }
  long long int ma = 0, cnt = 0;
  for (long long int i = 0; i <= sd.size() - 1; i++) {
    cnt += sd[i];
    ma = max(ma, cnt);
    if (cnt < 0) cnt = 0;
  }
  cnt = 0;
  for (long long int i = 0; i <= sd.size() - 1; i++) {
    cnt += -sd[i];
    ma = max(ma, cnt);
    if (cnt < 0) cnt = 0;
  }
  cout << ma << "\n";
}
