#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int N = 2e5;
long long po(int, int);
void solve() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  int m1 = 0, m2 = 0, bal = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1' && t[i] == '0') bal++;
    if (s[i] == '0' && t[i] == '1') bal--;
    m1 = max(m1, bal);
    m2 = min(m2, bal);
  }
  if (bal != 0)
    cout << "-1\n";
  else
    cout << m1 - m2 << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
long long po(int a, int b) {
  if (b == 0) return 1;
  long long ans = 1;
  if (b % 2 == 0) {
    ans = po(a, b / 2) % M;
    ans = (ans % M * ans % M) % M;
  } else {
    ans = po(a, (b - 1) / 2) % M;
    ans = (ans % M * ans % M * a) % M;
  }
  return ans % M;
}
