#include <bits/stdc++.h>
using namespace std;
const string TASK = "";
const int maxn = 1e3 + 1;
int n, i, a[maxn], b[maxn], p[maxn], ka, kb;
bool ca[maxn], cb[maxn];
void Enter() {
  cin >> n;
  for (i = 1; i <= n; ++i) cin >> a[i];
  for (i = 1; i <= n; ++i) cin >> b[i];
}
bool Check() {
  int cnt1, cnt2;
  cnt1 = cnt2 = 0;
  for (i = 1; i <= n; ++i) {
    if (a[i] != p[i]) cnt1++;
    if (b[i] != p[i]) cnt2++;
  }
  return cnt1 == 1 && cnt2 == 1;
}
void Solve() {
  fill(ca + 1, ca + n + 1, 0);
  fill(cb + 1, cb + n + 1, 0);
  fill(p + 1, p + n + 1, 0);
  for (i = 1; i <= n; ++i)
    if (a[i] == b[i]) p[i] = a[i];
  for (i = 1; i <= n; ++i) ca[a[i]] = 1;
  for (i = 1; i <= n; ++i) cb[b[i]] = 1;
  for (i = 1; i <= n; ++i) {
    if (ca[i] == 0) ka = i;
    if (cb[i] == 0) kb = i;
  }
  int i1, i2;
  i1 = i2 = 0;
  for (i = 1; i <= n; ++i) {
    if (p[i] == 0) {
      i2 = i1;
      i1 = i;
      p[i] = ka;
      ka = kb;
    }
  }
  if (i2 != 0 && !Check()) swap(p[i1], p[i2]);
  for (i = 1; i <= n; ++i) cout << p[i] << ' ';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Enter();
  Solve();
}
