#include <bits/stdc++.h>
bool Check(std::vector<int>& result);
int main() {
  int n = 0;
  std::cin >> n;
  std::vector<int> from(n), to(n);
  for (int i = 0; i < from.size(); i++) {
    std::cin >> from[i];
    from[i]--;
  }
  for (int i = 0; i < to.size(); i++) {
    std::cin >> to[i];
    to[i]--;
  }
  std::vector<int> changes;
  for (int i = 0; i < from.size(); i++)
    if (from[i] != to[i]) changes.push_back(i);
  std::vector<int> result(from);
  if (changes.size() == 1) {
    int index = changes[0];
    std::vector<bool> used(result.size());
    for (int i = 0; i < result.size(); i++) used[result[i]] = true;
    used[from[index]] = true;
    used[to[index]] = true;
    for (int i = 0; i < used.size(); i++) {
      if (!used[i]) {
        result[index] = i;
        break;
      }
    }
  } else if (changes.size() == 2) {
    int i = changes[0], j = changes[1];
    int a = from[i], b = to[i], c = from[j], d = to[j];
    result[i] = a;
    result[j] = d;
    if (!Check(result)) {
      result[i] = b;
      result[j] = c;
    }
  }
  for (int i = 0; i < result.size(); i++) std::cout << result[i] + 1 << ' ';
  std::cout << '\n';
  return 0;
}
bool Check(std::vector<int>& result) {
  std::vector<bool> used(result.size());
  for (int i = 0; i < result.size(); i++) {
    if (used[result[i]]) return false;
    used[result[i]] = true;
  }
  return true;
}
