#include <bits/stdc++.h>
using namespace std;
long long int caseno, n;
char s[1000006];
char t[1000006];
set<long long int> store[2];
set<long long int>::iterator it, it1;
void Input() {
  scanf("%lld", &n);
  scanf("%s", &s);
  scanf("%s", &t);
}
void Calculation() {
  for (int i = 0; i < n; i++) {
    if (s[i] != t[i]) {
      store[t[i] - '0'].insert(i);
    }
  }
  if (store[0].size() != store[1].size()) {
    puts("-1");
    return;
  }
  long long int res = 0;
  while (store[0].size()) {
    long long int pos0 = *store[0].begin();
    long long int pos1 = *store[1].begin();
    long long int indx = 0, last = 0;
    if (pos0 > pos1) indx = 1;
    res++;
    while (1) {
      it = store[indx].lower_bound(last);
      if (it == store[indx].end()) break;
      long long int posNow0 = *it;
      it1 = store[1 - indx].lower_bound(posNow0);
      if (it1 == store[1 - indx].end()) break;
      last = *it1;
      store[indx].erase(it);
      store[1 - indx].erase(it1);
    }
  }
  printf("%lld\n", res);
}
void Solve() {
  Input();
  Calculation();
}
int main() {
  int q;
  q = 1;
  caseno = 0;
  while (q--) {
    caseno++;
    Solve();
  }
  return 0;
}
