#include <bits/stdc++.h>
using namespace std;
const long long N = 200100;
long long n, cnt, ans, pos, r, x, y;
string s, t;
set<long long> a, b;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> s >> t;
  for (long long i = 0; i < n; i++) {
    cnt += s[i] - t[i];
    if (s[i] != t[i] && s[i] == '0')
      a.insert(i);
    else if (s[i] != t[i])
      b.insert(i);
  }
  if (cnt) {
    cout << -1;
    return 0;
  }
  for (; !a.empty();) {
    ans++;
    x = *a.begin(), y = *b.begin();
    a.erase(a.begin());
    b.erase(b.begin());
    pos = min(x, y);
    if (x < y)
      r = 0;
    else
      r = 1;
    for (;;) {
      if (!r) {
        auto le = a.lower_bound(y);
        if (le == a.end()) break;
        x = *le;
        auto ri = b.lower_bound(x);
        if (ri == b.end()) break;
        y = *ri;
      } else {
        auto ri = b.lower_bound(x);
        if (ri == b.end()) break;
        y = *ri;
        auto le = a.lower_bound(y);
        if (le == a.end()) break;
        x = *le;
      }
      a.erase(x);
      b.erase(y);
    }
  }
  cout << ans;
}
