#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, arr[1000], brr[1000], temp;
  cin >> n;
  for (i = 0; i < n; i++) cin >> arr[i];
  for (i = 0; i < n; i++) cin >> brr[i];
  int key[2], flag = 0;
  for (i = 0; i < n; i++) {
    if (arr[i] != brr[i]) {
      key[flag] = i;
      flag++;
    }
  }
  if (flag == 1) {
    for (i = 0; i < n; i++)
      if (count(arr, arr + n, i + 1) == 0) {
        arr[key[0]] = i + 1;
      }
  } else if (flag == 2) {
    temp = arr[key[0]];
    arr[key[0]] = brr[key[0]];
    if (count(arr, arr + n, arr[key[0]]) > 1 ||
        count(arr, arr + n, arr[key[1]]) > 1) {
      arr[key[0]] = temp;
      arr[key[1]] = brr[key[1]];
    }
  }
  for (i = 0; i < n; i++) cout << arr[i] << " ";
  return 0;
}
