#include <bits/stdc++.h>
using namespace std;
class TaskB {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int n;
    in >> n;
    vector<int> a(1001), b(1001);
    int used[1001];
    memset(used, 0, sizeof(used));
    for (int i = 0; i < n; i++) {
      in >> a[i];
      used[a[i]]++;
    }
    for (int i = 0; i < n; i++) in >> b[i];
    int zero = -1, two = -1;
    for (int i = 1; i <= n; i++) {
      if (used[i] == 2) two = i;
      if (used[i] == 0) zero = i;
    }
    for (int i = 0; i < n; i++) {
      if (a[i] == two) {
        a[i] = zero;
        break;
      }
    }
    int dist = 0;
    for (int i = 0; i < n; i++)
      if (a[i] != b[i]) dist++;
    if (dist == 1) {
      for (int i = 0; i < n; i++) out << a[i] << " ";
      return;
    }
    for (int i = 0; i < n; i++) {
      if (a[i] == zero) {
        a[i] = two;
        continue;
      }
      if (a[i] == two) {
        a[i] = zero;
        continue;
      }
    }
    for (int i = 0; i < n; i++) out << a[i] << " ";
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  TaskB solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
