#include <bits/stdc++.h>
using namespace std;
const int maxn = 1123456;
int n;
char s[maxn], t[maxn];
int main() {
  scanf("%d", &n);
  scanf("%s%s", s + 1, t + 1);
  int cnt = 0;
  for (int(i) = (1); (i) <= (n); (i)++) {
    if (s[i] == '0')
      cnt++;
    else
      cnt--;
    if (t[i] == '0')
      cnt--;
    else
      cnt++;
  }
  if (cnt) {
    puts("-1");
    return 0;
  }
  int ans[2] = {};
  for (int(i) = (1); (i) <= (n); (i)++)
    if (s[i] != t[i]) {
      if (s[i] == '0') {
        ans[0]++;
        if (ans[1] > 0) ans[1]--;
      } else {
        ans[1]++;
        if (ans[0] > 0) ans[0]--;
      }
    }
  printf("%d", ans[0] + ans[1]);
}
