#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  std::vector<int> b(n);
  std::map<int, int> ma;
  std::map<int, int> mb;
  std::set<int> st;
  int x = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    ma[a[i]]++;
    x ^= a[i];
    st.insert(a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    mb[b[i]]++;
    st.insert(b[i]);
  }
  if (a == b) {
    puts("0");
    return 0;
  }
  int less = -1;
  int over = -1;
  for (int e : st) {
    int c = ma[e] - mb[e];
    if (std::abs(c) >= 3) {
      puts("-1");
      return 0;
    }
    if (c == 2) {
      if (over != -1 || less != -1) {
        puts("-1");
        return 0;
      }
      over = e;
      less = e;
    } else if (c == -2) {
      if (over != -1 || less != -1) {
        puts("-1");
        return 0;
      }
      less = e;
      over = e;
    } else if (c == 1) {
      if (over != -1) {
        puts("-1");
        return 0;
      }
      over = e;
    } else if (c == -1) {
      if (less != -1) {
        puts("-1");
        return 0;
      }
      less = e;
    }
  }
  if ((less != -1) ^ (over != -1)) {
    puts("-1");
    return 0;
  }
  if (less != -1 && less != x) {
    puts("-1");
    return 0;
  }
  int unmatch = less == -1 && over == -1;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      unmatch++;
    }
  }
  std::cout << unmatch << std::endl;
}
