#include <bits/stdc++.h>
int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n;
  std::cin >> n;
  std::string s, t;
  std::cin >> s >> t;
  std::set<int> a[2];
  for (int i = 0; i < n; ++i)
    if (s[i] != t[i]) a[s[i] - '0'].insert(i);
  if (a[0].size() != a[1].size()) {
    std::cout << -1 << '\n';
    return 0;
  }
  int r = 0;
  while (a[0].size()) {
    ++r;
    int i = -1, j = (*a[1].begin() < *a[0].begin());
    for (;;) {
      auto it = a[j].upper_bound(i);
      if (it == a[j].end()) break;
      auto jt = a[j ^ 1].upper_bound(*it);
      if (jt == a[j ^ 1].end()) break;
      i = *jt;
      a[j].erase(it);
      a[j ^ 1].erase(jt);
    }
  }
  std::cout << r << '\n';
}
