#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char c = getchar();
  for (; c < 48 || c > 57; c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) x = (x << 1) + (x << 3) + c - 48;
  return x;
}
int n, a[1005], b[1005];
inline void init() {
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i <= n; ++i) b[i] = read();
}
int vis[1005];
inline void solve() {
  int x = 0, y = 0;
  for (int i = 1; i <= n; ++i)
    if (a[i] != b[i]) {
      if (!x)
        x = i;
      else
        y = i;
    } else
      vis[a[i]] = 1;
  if (!y) {
    for (int i = 1; i <= n; ++i)
      if (!vis[i]) a[x] = i;
  } else {
    if (!vis[a[x]] && !vis[b[y]])
      a[y] = b[y];
    else
      a[x] = b[x];
  }
  for (int i = 1; i <= n; ++i) printf("%d ", a[i]);
}
int main() {
  init();
  solve();
  return 0;
}
