#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), fin(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  set<int> xx;
  vector<int> temp;
  set<int> st;
  for (int i = 1; i <= n; i++) st.insert(i);
  int idx1 = -1, idx2 = -1;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      fin[i] = -1;
      if (idx1 == -1)
        idx1 = i;
      else
        idx2 = i;
    } else {
      xx.insert(a[i]);
      fin[i] = a[i];
      if (st.find(a[i]) != st.end()) st.erase(a[i]);
    }
  }
  int ct = 0;
  while (1) {
    bool found = false;
    ct++;
    for (int i = 0; i < n; i++) {
      if (fin[i] == -1) {
        found = true;
        if (xx.find(a[i]) != xx.end() && xx.find(b[i]) == xx.end()) {
          fin[i] = b[i];
          xx.insert(b[i]);
        } else if (xx.find(a[i]) == xx.end() && xx.find(b[i]) != xx.end()) {
          fin[i] = a[i];
          xx.insert(a[i]);
        } else if (xx.find(a[i]) != xx.end() && xx.find(b[i]) != xx.end()) {
          int ttt = *(st.begin());
          fin[i] = ttt;
          xx.insert(ttt);
          st.erase(ttt);
        }
      }
    }
    if (!found) break;
    if (ct > 10) {
      if (a[idx1] == a[idx2]) {
        fin[idx1] = a[idx1];
        fin[idx2] = b[idx2];
      } else {
        fin[idx1] = a[idx1];
        fin[idx2] = a[idx2];
      }
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << fin[i] << " ";
  }
}
