#include <bits/stdc++.h>
using namespace std;
int n;
int a[1005];
int b[1005];
int c[1005];
bool taken[1005];
vector<int> mis;
vector<int> mis_ind;
int main() {
  cin >> n;
  for (int i = 0; i != n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i != n; i++) {
    cin >> b[i];
    if (a[i] == b[i]) {
      taken[a[i]] = true;
      c[i] = a[i];
    } else {
      mis_ind.push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!taken[i]) {
      mis.push_back(i);
    }
  }
  if (mis_ind.size() == 1) {
    c[mis_ind[0]] = mis[0];
  } else {
    if (!taken[a[mis_ind[0]]] && !taken[b[mis_ind[1]]]) {
      c[mis_ind[0]] = a[mis_ind[0]];
      c[mis_ind[1]] = b[mis_ind[1]];
    } else if (!taken[a[mis_ind[1]]] && !taken[b[mis_ind[0]]]) {
      c[mis_ind[1]] = a[mis_ind[1]];
      c[mis_ind[0]] = b[mis_ind[0]];
    }
  }
  for (int i = 0; i != n; i++) {
    cout << c[i] << " ";
  }
  cout << endl;
}
