#include <bits/stdc++.h>
using namespace std;
int n, cur, Max, Min;
char s[1000015], t[1000015];
int main() {
  scanf("%d", &n);
  scanf("%s%s", s + 1, t + 1);
  for (int i = 1; i <= n; i++) {
    if (s[i] == t[i]) continue;
    if (t[i] == '0')
      cur--;
    else
      cur++;
    Max = max(Max, cur);
    Min = min(Min, cur);
  }
  if (cur != 0)
    printf("-1");
  else
    printf("%d", Max - Min);
  return 0;
}
