#include <bits/stdc++.h>
using namespace std;
int n;
int A[1005], B[1005];
int book[1005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> A[i];
  for (int i = 1; i <= n; i++) cin >> B[i];
  int x, y, z;
  for (int i = 1; i <= n; i++) {
    if (!book[A[i]])
      book[A[i]] = i;
    else
      x = i, y = book[A[i]];
  }
  for (int i = 1; i <= n; i++)
    if (!book[i]) z = i;
  int t = A[x];
  A[x] = z;
  int p = 0;
  for (int i = 1; i <= n; i++) {
    if (A[i] != B[i]) p++;
  }
  if (p != 1) {
    A[x] = t;
    A[y] = z;
    for (int i = 1; i <= n; i++) cout << A[i] << " ";
  } else {
    for (int i = 1; i <= n; i++) cout << A[i] << " ";
  }
  return 0;
}
