#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, i, c = 0, d = 0;
  cin >> n;
  string a, b, s1 = "", s2 = "";
  cin >> a >> b;
  for (i = 0; i < n; i++) {
    if (a[i] == '0') c++;
    if (b[i] == '0') d++;
    if (a[i] != b[i]) {
      s1 += a[i];
      s2 += b[i];
    }
  }
  if (a == b) {
    cout << 0;
    return 0;
  }
  if (c != d) {
    cout << "-1";
    return 0;
  }
  long long ans = 1;
  for (i = 0; i < s1.size() - 1; i++) {
    if (s1[i] == s1[i + 1]) break;
  }
  if (i == s1.size() - 1) {
    cout << 1;
    return 0;
  }
  long long one = 0, zero = 0;
  for (i = 0; i < s1.size(); i++) {
    if (s1[i] == '0') {
      if (one) {
        one--;
        zero++;
      } else
        zero++;
    } else {
      if (zero) {
        zero--;
        one++;
      } else
        one++;
    }
  }
  cout << one + zero;
  return 0;
}
