#include <bits/stdc++.h>
using lint = long long int;
using pii = std::pair<int, int>;
int aa[100100], bb[100100];
int main(void) {
  int N, cou = 0, xo = 0;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &aa[i]);
    xo ^= aa[i];
  }
  for (int i = 1; i <= N; i++) {
    scanf("%d", &bb[i]);
  }
  for (int i = 1; i <= N; i++) {
    if (aa[i] != bb[i]) {
      cou++;
    }
  }
  std::sort(aa + 1, aa + N + 1);
  std::sort(bb + 1, bb + N + 1);
  int ind1 = 1, ind2 = 1, W_A = 0, W_B = 0;
  while (ind1 <= N || ind2 <= N) {
    if (ind1 == N + 1 || aa[ind1] > bb[ind2]) {
      ind2++;
      W_A++;
    } else if (ind2 == N + 1 || aa[ind1] < bb[ind2]) {
      ind1++;
      W_B++;
    } else if (aa[ind1] == bb[ind2]) {
      ind1++, ind2++;
    }
  }
  if (W_B > 2) {
    printf("-1");
    return 0;
  }
  return 0;
}
