#include <bits/stdc++.h>
int T, n, ans[1000010], ans1, ans2, sum1, sum2, cnt;
char aa[1000010], bb[1000010];
int main() {
  scanf("%d%s%s", &n, aa + 1, bb + 1);
  for (int i = 1; i <= n; i++)
    if (aa[i] != bb[i])
      sum1 = std::max(0, sum1 + (aa[i] == '1' ? 1 : -1)),
      sum2 = std::max(0, sum2 + (aa[i] == '1' ? -1 : 1)),
      cnt += aa[i] == '1' ? 1 : -1, ans1 = std::max(ans1, sum1),
      ans2 = std::max(ans2, sum2);
  printf("%d\n", cnt == 0 ? std::max(ans1, ans2) : -1);
}
