#include <bits/stdc++.h>
using namespace std;
using lli = long long;
using lld = long double;
using ulli = unsigned long long int;
using pll = pair<lli, lli>;
using ttt = pair<lli, pll>;
using vttt = vector<ttt>;
using vll = vector<pll>;
using vl = vector<lli>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using cd = complex<lld>;
const double PI = acos(-1);
string get(string s) {
  sort(s.begin(), s.end());
  return s;
}
int tejas_919(int kkkk) {
  lli n, m, k, q, u, v, temp = 0, ans = 0;
  cin >> n;
  string s, t;
  cin >> s >> t;
  if (get(s) != get(t)) return cout << -1 << '\n', 0;
  int c0 = 0, c1 = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == t[i]) continue;
    if (s[i] == '0') {
      if (c1) c1--;
      c0++;
    } else {
      if (c0) c0--;
      c1++;
    }
  }
  cout << c0 + c1 << '\n';
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(10);
  int t = 1;
  for (int i = 0; i < t; i++) {
    tejas_919(i + 1);
  }
  {};
}
