#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const long long int inf64 = 1e18 + 5;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, i;
  cin >> n;
  string ss, t;
  cin >> ss >> t;
  int c0 = 0, c1 = 0;
  for (i = 0; i < n; i++) {
    if (ss[i] == '0')
      c0++;
    else
      c1++;
  }
  for (i = 0; i < n; i++) {
    if (t[i] == '0')
      c0--;
    else
      c1--;
  }
  if (c0 != 0 || c1 != 0)
    cout << -1;
  else {
    set<int> second[2];
    for (i = 0; i < n; i++) {
      if (ss[i] != t[i]) {
        if (ss[i] == '0')
          second[0].insert(i);
        else
          second[1].insert(i);
      }
    }
    int ans = 0;
    while (!second[0].empty() && !second[1].empty()) {
      if (*second[0].begin() < *second[1].begin()) {
        int curr = -1;
        while (!second[0].empty() && !second[1].empty()) {
          auto it2 = second[0].upper_bound(curr);
          if (it2 == second[0].end()) break;
          int x = *it2;
          auto it = second[1].upper_bound(x);
          if (it == second[1].end()) break;
          curr = *it;
          second[0].erase(it2);
          second[1].erase(it);
        }
      } else {
        int curr = -1;
        while (!second[0].empty() && !second[1].empty()) {
          auto it2 = second[1].upper_bound(curr);
          if (it2 == second[1].end()) break;
          int x = *it2;
          auto it = second[0].upper_bound(x);
          if (it == second[0].end()) break;
          curr = *it;
          second[1].erase(it2);
          second[0].erase(it);
        }
      }
      ++ans;
    }
    cout << ans << '\n';
  }
}
