#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int a[100009], b[100009], c[100009];
int x, y, t, k;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    if (c[a[i]]) {
      x = c[a[i]];
      y = i;
    }
    c[a[i]] = i;
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", b + i);
    if (i != x && i != y && a[i] != b[i]) k++;
  }
  for (int i = 1; i <= n; ++i)
    if (!c[i]) a[x] = i;
  if ((a[x] != b[x]) + (a[y] != b[y]) + k != 1) swap(a[x], a[y]);
  for (int i = 1; i <= n; ++i) printf("%d ", a[i]);
}
