#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
long long dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
long long dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
long long N;
long long a[110000], b[110000];
signed main() {
  cin >> N;
  for (long long i = 0; i < N; i++) cin >> a[i];
  for (long long i = 0; i < N; i++) cin >> b[i];
  long long ans = 0;
  for (long long i = 0; i < N; i++)
    if (a[i] != b[i]) ans++;
  if (ans == 0) {
    cout << ans << endl;
    return 0;
  }
  sort(a, a + N);
  sort(b, b + N);
  for (long long i = 0; i < N; i++)
    if (a[i] != b[i]) goto nene;
  cout << ans + 1 << endl;
  return 0;
nene:;
  for (long long i = 0; i < N; i++) a[N] ^= a[i];
  sort(a, a + N + 1);
  long long cur = 0;
  for (long long i = 0; i < N; i++) {
    if (a[cur] != b[i]) {
      cur++;
      if (a[cur] != b[i]) cur = -1;
    }
    cur++;
  }
  if (cur == N + 1)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
