#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void amin(T &x, const T &y) {
  if (y < x) x = y;
}
template <class T>
inline void amax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class Iter>
void rprintf(const char *fmt, Iter begin, Iter end) {
  for (bool sp = 0; begin != end; ++begin) {
    if (sp)
      putchar(' ');
    else
      sp = true;
    printf(fmt, *begin);
  }
  putchar('\n');
}
int N;
int A[1111], B[1111], P[1111];
bool C[1111];
void MAIN() {
  scanf("%d", &N);
  for (int i = 0, i_len = (N); i < i_len; ++i) scanf("%d", A + i);
  for (int i = 0, i_len = (N); i < i_len; ++i) scanf("%d", B + i);
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    memset(C, 0, sizeof C);
    for (int j = 0, j_len = (N); j < j_len; ++j) {
      if (j == i) continue;
      P[j] = A[j];
      C[P[j]] = true;
    }
    for (int j = 0, j_len = (N); j < j_len; ++j)
      if (!C[j + 1]) {
        P[i] = j + 1;
        C[j + 1] = true;
        break;
      }
    int cntA = 0, cntB = 0;
    bool per = true;
    memset(C, 0, sizeof C);
    for (int j = 0, j_len = (N); j < j_len; ++j) {
      if (A[j] == P[j]) cntA++;
      if (B[j] == P[j]) cntB++;
      if (C[P[j]]) per = false;
      C[P[j]] = 1;
    }
    if (per && cntA == N - 1 && cntB == N - 1) {
      rprintf("%d", P, P + N);
      return;
    }
  }
  rprintf("%d", A, A + N);
}
int main() {
  int TC = 1;
  for (int tc = 0, tc_len = (TC); tc < tc_len; ++tc) MAIN();
  return 0;
}
