#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a, b;
  for (int(i) = 0; (i) < (n); (i)++) {
    int v1;
    cin >> v1;
    a.push_back(v1);
  }
  for (int(i) = 0; (i) < (n); (i)++) {
    int v1;
    cin >> v1;
    b.push_back(v1);
  }
  int cnt = 0;
  for (int(i) = 0; (i) < (n); (i)++)
    if (a[i] != b[i]) cnt++;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int xr = 0;
  for (int(i) = 0; (i) < (n); (i)++) xr ^= a[i];
  int ct = 0;
  for (int(i) = 0; (i) < (n); (i)++) {
    if (a[i] != b[i]) ct++;
  }
  if (ct == 0) {
    cout << cnt + 1;
    return 0;
  }
  if (ct > 1) {
    cout << -1;
    return 0;
  }
  a.push_back(xr);
  sort(a.begin(), a.end());
  int flag = 0, j = -1;
  for (int(i) = 0; (i) < (n); (i)++) {
    j++;
    if (b[i] == a[j])
      continue;
    else if (flag == 0) {
      flag++;
      j++;
    } else {
      cout << -1;
    }
  }
  cout << cnt;
  return 0;
}
