#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 0;
  char ch = 0;
  while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
  while (isdigit(ch)) (x *= 10) += (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
void Ot(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) Ot(x / 10);
  putchar(x % 10 + 48);
}
void Print(int x, char til = '\n') {
  Ot(x);
  putchar(til);
}
const int MAXN = 1010;
vector<int> G;
set<int> st;
int n, sum;
int a[MAXN], b[MAXN], p[MAXN];
bool vis[MAXN];
signed main() {
  n = read();
  sum = (1 + n) * n / 2;
  for (register int i = 1; i <= n; i++) a[i] = read();
  for (register int i = 1; i <= n; i++) b[i] = read();
  for (register int i = 1; i <= n; i++) {
    if (a[i] != b[i])
      G.push_back(i);
    else
      p[i] = a[i], sum -= a[i], vis[a[i]] = 1;
  }
  if (G.size() == 2)
    if (vis[a[G[0]]] | vis[b[G[1]]])
      p[G[0]] = b[G[0]], p[G[1]] = a[G[1]];
    else
      p[G[0]] = a[G[0]], p[G[1]] = b[G[1]];
  else
    p[G[0]] = sum;
  for (register int i = 1; i <= n; i++) Print(p[i], ' ');
  return 0;
}
