#include <bits/stdc++.h>
using namespace std;
const int N = 510;
const int M = 100000;
const long long INF = 1e18;
int n, cntIn, cntOut;
int a[N], b[N], degIn[N], degOut[N];
pair<int, int> p[N];
vector<int> g[N];
bool used[N];
void compress() {
  for (int i = 0; i <= n; i++) p[i] = make_pair(a[i], i);
  for (int i = n + 1; i <= 2 * n; i++) p[i] = make_pair(b[i - n], i);
  sort(p, p + 2 * n + 1);
  int val = 1;
  for (int i = 0; i <= 2 * n; i++) {
    if (i > 1 && p[i].first != p[i - 1].first) val++;
    if (p[i].second <= n)
      a[p[i].second] = val;
    else
      b[p[i].second - n] = val;
  }
}
void dfs(int v) {
  used[v] = true;
  if (degIn[v] > degOut[v])
    cntIn++;
  else if (degIn[v] < degOut[v])
    cntOut++;
  for (int i = 0; i < g[v].size(); i++)
    if (!used[g[v][i]]) {
      dfs(g[v][i]);
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  int x = 0;
  for (int i = 1; i <= n; i++) x ^= a[i];
  a[0] = x;
  compress();
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] != b[i]) {
      ans++;
      degOut[b[i]]++;
      degIn[a[i]]++;
      g[b[i]].push_back(a[i]);
      g[a[i]].push_back(b[i]);
    }
  }
  memset(used, false, sizeof(used));
  bool flag = false;
  for (int i = 0; i <= 2 * n; i++) {
    if (!used[i]) {
      if (g[i].size() == 0) continue;
      cntIn = 0;
      cntOut = 0;
      dfs(i);
      if (!flag && used[i]) {
        flag = true;
        bool correct = (cntIn == cntOut ||
                        (cntIn == 1 && cntOut == 1 && degOut[x] > degIn[x]));
        if (!correct) {
          ans = -1;
          break;
        }
      } else {
        if (cntIn != 0 || cntOut != 0) {
          ans = -1;
          break;
        } else {
          ans++;
        }
      }
    }
  }
  for (int i = 0; i <= 2 * n; i++) {
    if (abs(degIn[i] - degOut[i]) > 1) {
      ans = -1;
      break;
    }
  }
  cout << ans;
  return 0;
}
