#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v;
vector<int> vv;
vector<int> V;
vector<int> VV;
map<int, deque<int> > want;
multiset<int> vs;
multiset<int> vvs;
map<int, int> mp;
bool changed[100002];
inline void dfs(int cur, int en) {
  changed[cur] = true;
  int val = v[cur];
  while (want[val].size() && changed[want[val].back()]) {
    want[val].pop_back();
  }
  if (want[val].size()) {
    dfs(want[val].back(), en);
  }
}
int solve() {
  memset(changed, false, sizeof(changed));
  want.clear();
  int z = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] != vv[i]) {
      want[vv[i]].push_back(i);
      z++;
    }
  }
  int cy = 0;
  for (int i = 0; i < n; i++) {
    if (changed[i] == false) {
      if (v[i] != vv[i]) {
        cy++;
        dfs(i, i);
      }
    }
  }
  return cy + z - 1;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    v.push_back(a);
  }
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    vv.push_back(a);
  }
  V = v;
  VV = vv;
  sort(V.begin(), V.end());
  sort(VV.begin(), VV.end());
  if (v == vv) {
    puts("0");
    return 0;
  }
  int ans = INT_MAX;
  int ans1 = 0;
  if (V == VV) {
    ans1 = solve();
    ans = ans1;
  }
  for (int i = 0; i < v.size(); i++) {
    mp[v[i]]++;
    mp[vv[i]]--;
  }
  int l_cnt = 0;
  int g_cnt = 0;
  int g_id = -1;
  int l_id = -1;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    if ((*it).second > 0) {
      g_cnt++;
      g_id = (*it).first;
    }
    if ((*it).second < 0) {
      l_cnt++;
      l_id = (*it).first;
    }
  }
  int X = 0;
  for (int i = 0; i < v.size(); i++) {
    X ^= v[i];
  }
  if (g_cnt <= 1 && l_cnt <= 1) {
    for (int i = 0; i < n; i++) {
      if (v[i] == X) {
        if (l_cnt == 0 && g_cnt == 0) {
        }
      } else {
        if (l_id == X && g_id == v[i]) {
          v[i] = X;
          ans = min(ans, solve());
        }
      }
      if (clock() / (double)(CLOCKS_PER_SEC) > 1.8) break;
    }
  }
  printf("%d\n", ans);
  return 0;
}
