#include <bits/stdc++.h>
using namespace std;
namespace Sol {
const int N = 200005;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') f = -1, ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return x * f;
}
int n;
map<vector<int>, int> Mapa, Mapb;
vector<int> q[10000005];
int d[10000005], t[10000005];
void Main() {
  n = read();
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 0; i < n; i++) a[i] = read(), a[n] ^= a[i];
  for (int i = 0; i < n; i++) b[i] = read(), b[n] ^= b[i];
  Mapb[b] = 1;
  Mapa[a] = 1;
  int head = 0, tail = 0;
  tail++, d[tail] = 1, t[tail] = 1, q[tail] = a;
  tail++, d[tail] = 1, t[tail] = 0, q[tail] = b;
  if (a == b) return (void)puts("0");
  while (head < tail) {
    vector<int> tmp = q[++head];
    if (t[head]) {
      for (int i = 0; i < n; i++) {
        swap(tmp[i], tmp[n]);
        if (Mapb[tmp]) {
          printf("%d", d[head] + Mapb[tmp] - 1);
          return;
        }
        if (Mapa[tmp]) {
          swap(tmp[i], tmp[n]);
          continue;
        }
        Mapa[tmp] = d[++tail] = d[head] + 1;
        q[tail] = tmp;
        t[tail] = 1;
        swap(tmp[i], tmp[n]);
      }
    } else {
      for (int i = 0; i < n; i++) {
        swap(tmp[i], tmp[n]);
        if (Mapa[tmp]) {
          printf("%d", d[head] + Mapa[tmp] - 1);
          return;
        }
        if (Mapb[tmp]) {
          swap(tmp[i], tmp[n]);
          continue;
        }
        Mapb[tmp] = d[++tail] = d[head] + 1;
        q[tail] = tmp;
        t[tail] = 0;
        swap(tmp[i], tmp[n]);
      }
    }
  }
}
}  // namespace Sol
int main() {
  Sol ::Main();
  return 0;
}
