#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1111];
int b[1111];
int c[1111];
int vis[1111];
int pos[5];
int cntp;
int main() {
  scanf("%d", &n);
  bool flag = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    vis[a[i]]++;
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
    if (a[i] != b[i]) {
      pos[++cntp] = i;
    }
  }
  int dvis;
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      dvis = i;
      break;
    }
  if (cntp == 1) {
    a[pos[1]] = dvis;
  } else {
    if (b[pos[1]] == dvis && vis[a[pos[1]]] > 1)
      a[pos[1]] = dvis;
    else
      a[pos[2]] = dvis;
  }
  for (int i = 1; i <= n; ++i) printf("%d ", a[i]);
  return 0;
}
