#include <bits/stdc++.h>
using namespace std;
int solve(int n, vector<int> const& a, vector<int> const& b) {
  if (a == b) {
    return 0;
  }
  int sum_a = accumulate(begin(a), end(a), 0, bit_xor<int>());
  int removed;
  {
    map<int, int> cnt;
    for (int a_i : a) {
      cnt[a_i] += 1;
    }
    cnt[sum_a] += 1;
    for (int b_i : b) {
      if (cnt.count(b_i)) {
        cnt[b_i] -= 1;
        if (cnt[b_i] == 0) {
          cnt.erase(b_i);
        }
      }
    }
    assert(not cnt.empty());
    if (cnt.size() >= 2 or cnt.begin()->second >= 2) {
      assert(false);
      return -1;
    }
    removed = cnt.begin()->first;
  }
  int mismatch = 0;
  for (int i = 0; (i) < int(n); ++(i)) {
    mismatch += (a[i] != b[i]);
  }
  int component = 0;
  {
    map<int, set<int> > g;
    for (int i = 0; (i) < int(n); ++(i)) {
      if (a[i] != b[i]) {
        g[b[i]].insert(a[i]);
      }
    }
    set<int> used;
    function<void(int)> go = [&](int a_i) {
      used.insert(a_i);
      for (int a_j : g[a_i])
        if (not used.count(a_j)) {
          go(a_j);
        }
    };
    for (int i = 0; (i) < int(n); ++(i))
      if (not used.count(a[i])) {
        if (not g.count(a[i])) continue;
        component += 1;
        go(a[i]);
      }
  }
  return mismatch + component - (find(begin(b), end(b), sum_a) != b.end());
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; (i) < int(n); ++(i)) scanf("%d", &a[i]);
  vector<int> b(n);
  for (int i = 0; (i) < int(n); ++(i)) scanf("%d", &b[i]);
  int result = solve(n, a, b);
  printf("%d\n", result);
  return 0;
}
