#include <bits/stdc++.h>
using namespace std;
int n, a[1010], b[1010], c[1010], x1, x2, y;
bool Sol(int x, int y) {
  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (i == x && b[i] != y)
      cnt++;
    else if (i != x && b[i] != a[i])
      cnt++;
  if (cnt == 1) {
    a[x] = y;
    return 1;
  } else
    return 0;
}
int main() {
  memset(c, -1, sizeof(c));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (c[a[i]] != -1) x1 = c[a[i]], x2 = i;
    c[a[i]] = i;
  }
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++)
    if (c[i] == -1) y = i;
  if (!Sol(x1, y)) Sol(x2, y);
  for (int i = 0; i < n; i++) printf("%d ", a[i]);
  printf("\n");
  return 0;
}
