#include <bits/stdc++.h>
using namespace std;
void solve() {
  int i = 0, j, k = 0, ans = 0, r, len, f = 0, m = 0, n, l = 0, p;
  string s, t;
  cin >> n;
  cin >> s >> t;
  vector<int> ind;
  map<char, int> freq;
  for (i = (0); i < (n) && !(0); i++) freq[s[i]]++;
  for (i = (0); i < (n) && !(f); i++) {
    freq[t[i]]--;
    if (freq[t[i]] < 0) f = 1;
    if (s[i] != t[i]) ind.push_back(i);
  }
  k = 0;
  int maxi = 0, mini = 0;
  for (i = (0); i < (ind.size()) && !(0); i++) {
    if (s[ind[i]] == '1')
      k++;
    else
      k--;
    maxi = max(maxi, k);
    mini = min(mini, k);
  }
  if (f)
    cout << "-1";
  else
    cout << maxi - mini;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1, i = 1;
  while (t--) {
    solve();
  }
}
