#include <bits/stdc++.h>
using namespace std;
int a[1003], b[1003], ans[1003];
int main() {
  int t, k, i, j, n, m, x, y, c, q;
  cin >> n;
  c = 0;
  for (i = 0; i < n; i++) cin >> a[i];
  for (j = 0; j < n; j++) {
    cin >> b[j];
    if (a[j] != b[j]) c++;
  }
  set<int> s;
  if (c == 1) {
    for (i = 0; i < n; i++) {
      if (a[i] == b[i]) {
        ans[i] = a[i];
        s.insert(a[i]);
      }
    }
    for (i = 0; i < n; i++)
      if (ans[i] == 0) break;
    for (j = 1; j <= n; j++)
      if (s.find(j) == s.end()) break;
    ans[i] = j;
  } else if (c == 2) {
    for (i = 0; i < n; i++) {
      if (a[i] == b[i]) {
        ans[i] = a[i];
        s.insert(a[i]);
      }
    }
    for (j = 1; j <= n; j++)
      if (s.find(j) == s.end()) break;
    x = j;
    for (j = j + 1; j <= n; j++)
      if (s.find(j) == s.end()) break;
    y = j;
    for (i = 0; i < n; i++)
      if (a[i] != b[i]) break;
    for (j = i + 1; j < n; j++)
      if (a[j] != b[j]) break;
    if ((a[i] == x || b[i] == x) && (a[j] == y || b[j] == y)) {
      ans[i] = x;
      ans[j] = y;
    } else {
      ans[i] = y;
      ans[j] = x;
    }
  }
  for (i = 0; i < n; i++) cout << ans[i] << " ";
  return 0;
}
