#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int cnt = 0;
  int ch[1010], sh[1010];
  int q[1010], sav[1010], p[1010];
  int a[1010], b[1010];
  int one, two;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> ch[i];
    q[ch[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cin >> sh[i];
    p[sh[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (p[i] == 0) two = i;
    if (q[i] == 0) one = i;
  }
  for (int i = 1; i <= n; i++) {
    if (ch[i] != sh[i]) sav[cnt++] = i;
  }
  if (cnt == 1) {
    sh[sav[0]] = two;
    for (int i = 1; i <= n; i++) {
      if (i != 1) cout << " ";
      cout << sh[i];
    }
    cout << endl;
    return 0;
  }
  if (sh[sav[0]] == one && q[ch[sav[0]]] > 1)
    ch[sav[0]] = one;
  else
    ch[sav[1]] = one;
  for (int i = 1; i <= n; i++) {
    if (i != 1) cout << " ";
    cout << ch[i];
  }
  cout << endl;
  return 0;
}
