#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int n;
string a, b;
vector<pair<int, int>> f;
void insert(pair<int, int> u) {
  if (int((f).size()) and f.back().first == u.first) {
    f.back().second += u.second;
  } else if (u.second) {
    f.push_back(u);
  }
}
void fix() {
  if (f.back().first == f[0].first) {
    f[0].second += f.back().second;
    f.pop_back();
  }
}
void solve() {
  fix();
  vector<pair<int, int>> g(f);
  f.clear();
  for (auto &u : g) {
    u.second -= 1, insert(u);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> a >> b;
  int ca = 0, cb = 0;
  for (int i = (0); i < (n); ++i) {
    ca += a[i] - '0';
    cb += b[i] - '0';
    if (a[i] != b[i]) {
      insert(make_pair(a[i] - '0', 1));
    }
  }
  if (ca != cb) {
    cout << "-1\n";
  } else {
    int res = 0;
    while (int((f).size())) {
      solve();
      res += 1;
    }
    cout << res << '\n';
  }
  return 0;
}
