#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, a[N], b[N], ans, tot, flag = 1;
map<int, int> fa;
set<int> st;
int find(int x) {
  if (fa.count(x))
    return fa[x] = find(fa[x]);
  else
    return x;
}
void merge(int a, int b) {
  a = find(a), b = find(b);
  if (a == b) return;
  fa[a] = b;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), tot ^= a[i];
  a[n + 1] = tot, tot = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]), tot ^= b[i];
  b[n + 1] = tot;
  for (int i = 1; i <= n; i++)
    if (a[i] != b[i]) {
      merge(a[i], b[i]);
      st.insert(a[i]), st.insert(b[i]);
      ans++;
    }
  if (!ans) return puts("0"), 0;
  for (map<int, int>::iterator it = fa.begin(); it != fa.end(); it++) {
    if (find((*it).first) != ((*it).first)) ans--;
  }
  printf("%d", ans - (a[n + 1] != b[n + 1]) + (int)st.size());
  return 0;
}
