#include <bits/stdc++.h>
using namespace std;
inline void boost() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
int a[1003], b[1003], ans[1003];
int n;
int used[1003];
bool check() {
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (ans[i] != b[i]) cnt += 1;
  }
  return cnt == 1;
}
inline void solve() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int i = 0; i < n; ++i) {
    ans[i] = a[i];
  }
  for (int i = 0; i < n + 1; ++i) used[i] = -1;
  int r = 0, l = 0, p1 = 0, p2 = 0;
  for (int i = 0; i < n; ++i) {
    if (used[a[i]] == -1) {
      used[a[i]] = i;
    } else {
      r = a[i];
      p1 = i;
      p2 = used[a[i]];
    }
  }
  for (int i = 1; i <= n; ++i)
    if (used[i] == -1) {
      l = i;
      break;
    }
  ans[p1] = r;
  ans[p2] = l;
  if (check()) {
    for (int i = 0; i < n; ++i) {
      cout << ans[i] << ' ';
    }
  } else {
    ans[p1] = l;
    ans[p2] = r;
    for (int i = 0; i < n; ++i) cout << ans[i] << ' ';
  }
}
int main() {
  boost();
  solve();
}
