#include <bits/stdc++.h>
using namespace std;
char s1[1000005], s2[1000005];
int main() {
  int km = 0, kn = 0, n, k = 0;
  cin >> n >> s1 >> s2;
  for (int i = 0; i < n; i++) {
    if (s1[i] == '1' && s2[i] == '0') k++;
    if (s1[i] == '0' && s2[i] == '1') k--;
    km = max(km, k);
    kn = min(kn, k);
  }
  if (k != 0)
    printf("-1");
  else
    printf("%d", km - kn);
  return 0;
}
