#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int a[N], b[N], v[N];
set<int> st;
vector<int> temp, left;
int n;
bool check() {
  int c1 = 0, c2 = 0;
  for (int i = 0; i < n; i++)
    if (a[i] != v[i]) c1++;
  for (int i = 0; i < n; i++)
    if (b[i] != v[i]) c2++;
  return ((c1 == 1 && c2 == 1) ? 1 : 0);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    st.insert(i);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    if (a[i] == b[i]) {
      st.erase(a[i]);
      v[i] = a[i];
    } else
      temp.push_back(i);
  }
  for (int i = 0; i < temp.size(); i++) {
    v[temp[i]] = *(st.begin());
    st.erase(st.begin());
  }
  if (!check()) {
    assert(temp.size() == 2);
    swap(v[temp[0]], v[temp[1]]);
  }
  for (int i = 0; i < n; i++) {
    printf("%d ", v[i]);
  }
  return 0;
}
