#include <bits/stdc++.h>
const int MX = 1010;
using namespace std;
int a[MX], b[MX], c[MX];
bool ok[MX];
vector<int> k;
vector<int> ans;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  int h = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == b[i]) {
      ok[a[i]] = 1;
      c[i] = a[i];
    } else {
      h++;
      k.push_back(i);
    }
  }
  for (int i = 1; i <= n; i++)
    if (ok[i] == 0) ans.push_back(i);
  c[k[0]] = ans[0];
  if (h > 1) c[k[1]] = ans[1];
  int cn = 0, cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (c[i] != a[i]) cnt++;
    if (c[i] != b[i]) cn++;
  }
  if (cn == 1 && cnt == 1)
    ;
  else if (h > 1)
    swap(c[k[0]], c[k[1]]);
  for (int i = 1; i <= n; i++) cout << c[i] << " ";
  return 0;
}
