#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j = 0, k = 0, n, x = 0, y = 0, z = 0, ans = 0;
  cin >> n;
  string s, t;
  cin >> s >> t;
  int a[n];
  for (i = 0; i < n; i++) {
    if (s[i] != t[i]) {
      if (s[i] == '1')
        a[i] = 1;
      else
        a[i] = -1;
    } else
      a[i] = 0;
    if (s[i] == '1') x++;
    if (t[i] == '1') z++;
  }
  if (x != z)
    cout << "-1";
  else {
    for (i = 0; i < n; i++) {
      k = k + a[i];
      if (k < 0) k = 0;
      ans = max(ans, k);
    }
    k = 0;
    for (i = 0; i < n; i++) {
      k = k + (-1) * a[i];
      if (k < 0) k = 0;
      ans = max(ans, k);
    }
    cout << ans;
  }
}
