#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, k;
string S, T;
string s;
void nhap() {
  cin >> n >> S >> T;
  S = " " + S;
  T = " " + T;
}
bool xet(string A, string B) {
  int dem[3];
  dem[0] = dem[1] = 0;
  for (int i = int(1); i <= int(n); i++) dem[A[i] - '0']++;
  for (int i = int(1); i <= int(n); i++) dem[B[i] - '0']--;
  if (!dem[0] && !dem[1]) return true;
  return false;
}
void chuyen(string A, string B) {
  s = " ";
  for (int i = int(1); i <= int(n); i++)
    if (A[i] != B[i]) s += A[i];
}
void xuli() {
  if (!xet(S, T)) {
    cout << -1 << "\n";
    return;
  }
  chuyen(S, T);
  int minn = 0, maxx = 0, ct = 0;
  for (int i = int(1); i <= int(s.size() - 1); i++) {
    if (s[i] == '1')
      ct++;
    else
      ct--;
    minn = min(minn, ct);
    maxx = max(maxx, ct);
  }
  cout << maxx - minn << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  nhap();
  xuli();
}
