#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) { cout << "NEXT\n"; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
template <typename... T>
void rd(T&... args) {
  ((cin >> args), ...);
}
template <typename... T>
void ps(T... args) {
  ((cout << args << ' '), ...);
  cout << '\n';
}
const long long MOD = 1e9 + 7, MOD1 = 998244353LL, MAX = 1e6 + 5;
const char nl = '\n';
const int INF = 1e9 + 5;
int n;
string s, t;
void solve() {
  cin >> n >> s >> t;
  int ans = 0, q01 = 0, q10 = 0, t01 = 0, t10 = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0' && t[i] == '1') {
      t01++;
      if (q10) {
        q10--;
      } else {
        ans++;
      }
      q01++;
    } else if (s[i] == '1' && t[i] == '0') {
      t10++;
      if (q01) {
        q01--;
      } else {
        ans++;
      }
      q10++;
    }
  }
  if (t10 != t01) {
    cout << "-1\n";
    return;
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int __ = 1;
  while (__--) {
    solve();
  }
  return 0;
}
