#include <bits/stdc++.h>
using namespace std;
int n, a[10005], b[10005], ans[10005];
bool vis[10005];
inline void read(int &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = 10 * x + c - '0';
    c = getchar();
  }
  x *= f;
}
void geta() {
  for (int k = 1; k <= n; k++) {
    memset(vis, 0, sizeof(vis));
    bool flag = 1;
    for (int i = 1; i <= n; i++)
      if (i != k) {
        if (vis[a[i]]) {
          flag = 0;
          break;
        }
        vis[a[i]] = 1;
      }
    if (!flag) continue;
    int p = 0;
    for (int i = 1; i <= n; i++)
      if (!vis[i]) p = i;
    for (int i = 1; i <= n; i++)
      if (i != k)
        ans[i] = a[i];
      else
        ans[i] = p;
    int cnt = 0;
    for (int i = 1; i <= n; i++)
      if (ans[i] != b[i]) cnt++;
    if (cnt == 1) break;
  }
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(a[i]);
  for (int i = 1; i <= n; i++) read(b[i]);
  geta();
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
