#include <bits/stdc++.h>
using namespace std;
int n;
int a[1111], b[1111], p[1111];
int tmp[1111], diff[1111];
bool check[1111];
int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  int cnt = 1, dif = 0, cntdif = 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] == b[i]) {
      p[i] = a[i];
      check[a[i]] = true;
    } else {
      dif++;
      diff[cntdif++] = i;
    }
  }
  for (int i = 1; i <= n; i++)
    if (!check[i]) tmp[cnt++] = i;
  do {
    int tmp1 = 1, cnta = 0, cntb = 0, cntc = 1;
    for (int i = 1; i <= n; i++)
      if (!p[i]) p[i] = tmp[tmp1++];
    for (int i = 1; i <= n; i++) {
      if (p[i] != a[i]) cnta++;
      if (p[i] != b[i]) cntb++;
    }
    if (cnta == 1 && cntb == 1) break;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j < cnt; j++)
        if (p[i] == tmp[j]) p[i] = 0;
  } while (next_permutation(tmp + 1, tmp + 1 + cnt));
  for (int i = 1; i <= n; i++) printf("%d ", p[i]);
  printf("\n");
  return false;
}
