#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  string s, t;
  set<long long int> z, o;
  cin >> s >> t;
  for (long long int i = 0; i < (n); i++) {
    if (s[i] != t[i]) {
      if (s[i] == '1')
        o.insert(i);
      else
        z.insert(i);
    }
  }
  long long int ans = -1;
  if (o.size() == z.size()) {
    ans = 0;
    while (o.size()) {
      if (*o.begin() < *z.begin()) {
        long long int cur = *o.begin();
        while (z.upper_bound(cur) != z.end()) {
          if (o.lower_bound(*z.lower_bound(cur)) != o.end()) {
            long long int nxt = *o.lower_bound(*z.lower_bound(cur));
            z.erase(*z.lower_bound(cur));
            o.erase(cur);
            cur = nxt;
          } else {
            z.erase(*z.lower_bound(cur));
            o.erase(cur);
            break;
          }
        }
        ans++;
      } else {
        long long int cur = *z.begin();
        while (o.lower_bound(cur) != o.end()) {
          if (z.lower_bound(*o.lower_bound(cur)) != z.end()) {
            long long int nxt = *z.lower_bound(*o.lower_bound(cur));
            o.erase(*o.lower_bound(cur));
            z.erase(cur);
            cur = nxt;
          } else {
            o.erase(*o.lower_bound(cur));
            z.erase(cur);
            break;
          }
        }
        ans++;
      }
    }
  }
  cout << ans;
}
