#include <bits/stdc++.h>
using namespace std;
long long n, a[1024], b[1024], c[1024], t[4], dd, d, have[1024];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] != a[i]) {
      c[d] = i;
      d++;
    } else {
      have[a[i]]++;
      have[b[i]]++;
    }
  }
  dd = 0;
  for (int i = 1; i <= n; i++) {
    if (have[i] == 0) {
      t[dd] = i;
      dd++;
    }
  }
  if (d == 1) {
    a[c[0]] = t[0];
  } else {
    int br = 0, br1 = 0;
    for (int i = 0; i < 2; i++) {
      if (a[c[i]] != t[i]) br++;
      if (b[c[i]] != t[i]) br1++;
    }
    if (br == 1 && br1 == 1) {
      a[c[0]] = t[0];
      a[c[1]] = t[1];
    } else {
      a[c[0]] = t[1];
      a[c[1]] = t[0];
    }
  }
  for (int i = 0; i < n - 1; i++) {
    cout << a[i] << " ";
  }
  cout << a[n - 1] << endl;
  return 0;
}
