#include <bits/stdc++.h>
using namespace std;
int a[1005], b[1005], p[1005], flag[1005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i < (n + 1); i++) scanf("%d", &a[i]);
  for (int i = (1); i < (n + 1); i++) scanf("%d", &b[i]);
  int cnt = 0;
  for (int i = (1); i < (n + 1); i++)
    if (a[i] == b[i]) {
      flag[a[i]]++;
      p[i] = a[i];
      cnt++;
    }
  if (cnt == n) {
    int aa = 0, bb = 0;
    for (int i = (1); i < (n + 1); i++) {
      if (flag[i] == 2)
        aa = i;
      else if (flag[i] == 0)
        bb = i;
    }
    for (int i = (1); i < (n + 1); i++)
      if (p[i] == aa) {
        p[i] = bb;
        break;
      }
  } else if (cnt == n - 1) {
    int aa = 0;
    for (int i = (1); i < (n + 1); i++)
      if (flag[i] == 0) aa = i;
    for (int i = (1); i < (n + 1); i++)
      if (p[i] == 0) p[i] = aa;
  } else {
    int aa = 0, bb = 0;
    for (int i = (1); i < (n + 1); i++)
      if (flag[i] == 0) {
        if (aa == 0)
          aa = i;
        else
          bb = i;
      }
    int pa = 0, push_back = 0;
    for (int i = (1); i < (n + 1); i++)
      if (p[i] == 0) {
        if (pa == 0)
          pa = i;
        else
          push_back = i;
      }
    p[pa] = aa;
    p[push_back] = bb;
    if (p[pa] == a[pa] && p[push_back] == b[push_back] ||
        p[pa] == b[pa] && p[push_back] == a[push_back])
      ;
    else
      swap(p[pa], p[push_back]);
  }
  for (int i = (1); i < (n + 1); i++) printf("%d%c", p[i], i == n ? '\n' : ' ');
  return 0;
}
