#include <bits/stdc++.h>
using namespace std;
int a[10000], b[10000], p[10000], used[10000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  int x = -1, y = -1;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i])
      p[i] = a[i], used[a[i]] = 1;
    else {
      (x == -1 ? x : y) = i;
    }
  }
  int u = -1, v = -1;
  for (int i = 1; i <= n; i++)
    if (!used[i]) (u == -1 ? u : v) = i;
  if (y == -1) {
    p[x] = u;
  } else {
    if ((a[x] == u || b[x] == u) && (a[y] == v || b[y] == v)) swap(u, v);
    p[x] = v, p[y] = u;
  }
  for (int i = 0; i < n; i++) printf("%d ", p[i]);
  printf("\n");
}
