#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int a[maxn], b[maxn];
int p[maxn];
int main() {
  int n;
  cin >> n;
  int x, y;
  x = maxn;
  y = maxn;
  set<int> sa, sb;
  memset(p, 0, sizeof(p));
  for (int i = 1; i <= n; i++) {
    sa.insert(i);
    sb.insert(i);
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[a[i]]++;
    if (sa.count(a[i])) sa.erase(a[i]);
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    if (sb.count(b[i])) sb.erase(b[i]);
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] != b[i]) cnt++;
    if (cnt == 1) x = min(x, i);
    if (cnt == 2) y = min(y, i);
  }
  if (cnt == 1) {
    for (auto gg : sa) a[x] = gg;
  } else {
    int xx;
    int yy;
    for (auto gg : sa) xx = gg;
    for (auto gg : sb) yy = gg;
    if (b[x] == xx && p[a[x]] == 2)
      a[x] = xx;
    else
      a[y] = xx;
  }
  for (int i = 1; i <= n; i++) cout << a[i] << " ";
  return 0;
}
