#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 6;
int a[MAX_N];
int b[MAX_N];
int main() {
  int n;
  scanf("%d", &n);
  vector<int> v1, v2;
  int kirino = 0;
  for (int i = 1; n >= i; i++) {
    scanf("%d", &a[i]);
    v1.push_back(a[i]);
    kirino ^= a[i];
  }
  for (int i = 1; n >= i; i++) {
    scanf("%d", &b[i]);
    v2.push_back(b[i]);
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  int dif = 0;
  int haha = -1;
  int meruru = -1;
  for (int i = 0; n > i; i++) {
    dif += (v1[i] != v2[i]);
    if (v1[i] != v2[i]) {
      if (v2[i] != kirino)
        dif = 2;
      else {
        meruru = v1[i];
      }
    }
  }
  if (dif >= 2) {
    puts("-1");
    return 0;
  }
  if (dif == 1) {
    bool can = false;
    int ans = 0;
    for (int i = 1; n >= i; i++) {
      ans += (a[i] != b[i]);
      if (a[i] == meruru && b[i] != kirino) can = true;
    }
    if (can)
      printf("%d\n", ans);
    else {
      if (ans == 1)
        puts("1");
      else
        printf("%d\n", ans + 1);
    }
  } else {
    int ans = 0;
    for (int i = 1; n >= i; i++) {
      ans += (a[i] != b[i]);
    }
    if (ans == 0)
      puts("0");
    else
      printf("%d\n", ans + 1);
  }
}
