#include <bits/stdc++.h>
using namespace std;
void _split(vector<string>& vc, const string& str, char ch) {
  string temp;
  for (int i = 0; i <= str.size(); i++)
    if (i == str.size() || str[i] == ch) {
      vc.emplace_back(temp);
      temp = "";
    } else {
      temp += str[i];
    }
}
void _output(vector<string>::iterator _) {
  cerr << '\n';
  cerr.flush();
}
template <typename T, typename... Args>
void _output(vector<string>::iterator it, T val, Args... args) {
  cerr << *it << " = " << val << "   ";
  _output(++it, args...);
}
const size_t MAX_N = 1000 + 5;
int n, a[MAX_N], b[MAX_N], cnt[MAX_N];
bool used[MAX_N];
inline bool check() {
  int cnt = 0;
  memset(used, 0, sizeof used);
  for (int i = 0; i < n; i++)
    if (a[i] != b[i]) cnt++;
  if (cnt != 1) return false;
  for (int i = 0; i < n; i++) used[a[i]] = true;
  for (int i = 1; i <= n; i++)
    if (!used[i]) return false;
  return true;
}
int main() {
  int diff_cnt = 0, i, j, k;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", a + i);
  for (i = 0; i < n; i++) scanf("%d", b + i);
  for (i = 0; i < n; i++) diff_cnt += a[i] != b[i];
  if (!diff_cnt) {
    for (i = 0; i < n; i++) cnt[a[i]]++;
    for (i = 0; i < n; i++) cnt[b[i]]++;
    for (j = 1; j <= n; j++)
      if (cnt[j] == 4) break;
    for (k = 1; k <= n; k++)
      if (cnt[k] == 0) break;
    for (i = 0; i < n; i++)
      if (a[i] == j) {
        printf("%d ", k);
        break;
      } else {
        printf("%d ", a[i]);
      }
    for (; i < n; i++) printf("%d ", a[i]);
  } else if (diff_cnt == 1) {
    for (i = 0; i < n; i++)
      if (a[i] == b[i]) cnt[a[i]]++;
    for (j = 1; j <= n; j++)
      if (!cnt[j]) break;
    for (i = 0; i < n; i++)
      if (a[i] == b[i])
        printf("%d ", a[i]);
      else
        printf("%d ", j);
  } else {
    vector<int> lft, pos;
    for (i = 0; i < n; i++)
      if (a[i] == b[i])
        cnt[a[i]]++;
      else
        pos.emplace_back(i);
    for (i = 1; i <= n; i++)
      if (!cnt[i]) lft.emplace_back(i);
    for (int x : pos)
      for (int l : lft)
        if (l != a[x]) {
          int t = a[x];
          a[x] = l;
          if (check()) {
            for (i = 0; i < n; i++) printf("%d ", a[i]);
            return 0;
          }
          a[x] = t;
        }
  }
}
