#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, k;
  cin >> n;
  int A[n], B[n], index[n], flag[n + 1];
  for (i = 0; i < n; i++) {
    cin >> A[i];
    flag[i] = 0;
  }
  flag[n] = 0;
  j = 0;
  for (i = 0; i < n; i++) {
    cin >> B[i];
    if (A[i] != B[i]) {
      index[j] = i;
      j++;
    } else {
      flag[A[i]] = 1;
    }
  }
  if (j == 2) {
    k = 0;
    for (i = 0; i < n; i++) {
      if (index[k] == i) {
        if (flag[B[i]] == 0 && flag[A[i]] == 0 && k == 0) {
          if (flag[B[index[k + 1]]] == 1) {
            cout << B[i] << " ";
            flag[B[i]] = 1;
          } else {
            cout << A[i] << " ";
            flag[A[i]] = 1;
          }
        } else if (flag[B[i]] == 0) {
          cout << B[i] << " ";
          flag[B[i]] = 1;
        } else {
          cout << A[i] << " ";
          flag[A[i]] = 1;
        }
        k++;
      } else
        cout << A[i] << " ";
    }
  } else if (j == 1) {
    for (i = 0; i < n; i++) {
      if (index[0] == i) {
        for (k = 1; k <= n; k++) {
          if (flag[k] == 0 && k != A[i] && k != B[i]) {
            cout << k << " ";
            break;
          }
        }
      } else
        cout << A[i] << " ";
    }
  }
  return 0;
}
