#include <bits/stdc++.h>
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
using namespace std;
int P[1005], Q[1005];
int V[1005], R[1005], F[1005];
int main() {
  int n;
  scanf("%d", &n);
  int m = 0, a[1005], k = 0, b[1005], k1 = 0;
  memset(V, 0, sizeof(V));
  memset(R, 0, sizeof(R));
  for (long long i = 0; i < n; i++) {
    scanf("%d", &P[i]);
    V[P[i]]++;
  }
  for (long long i = 0; i < n; i++) {
    scanf("%d", &Q[i]);
    R[Q[i]]++;
    if (P[i] != Q[i]) a[k++] = i;
  }
  if (k == 0) {
    for (long long i = 1; i < n + 1; i++) {
      if (V[i] > 1) a[k++] = i;
      if (V[i] == 0) b[k1++] = i;
    }
    for (long long i = 0; i < n; i++)
      if (P[i] == a[0]) {
        P[i] = b[0];
        break;
      }
    for (long long i = 0; i < n; i++)
      if (i == 0)
        cout << P[i];
      else
        cout << " " << P[i];
    cout << endl;
  } else if (k == 1) {
    int ans = a[0], ans1;
    for (long long i = 1; i < n + 1; i++) {
      if (V[i] == 0) {
        ans1 = i;
        break;
      }
    }
    P[ans] = ans1;
    for (long long i = 0; i < n; i++)
      if (i == 0)
        cout << P[i];
      else
        cout << " " << P[i];
    cout << endl;
  } else {
    int p1 = a[0], p2 = a[1];
    V[P[p1]]--;
    V[P[p2]]--;
    int k2 = 0;
    for (long long i = 1; i < n + 1; i++) {
      if (V[i] == 0) a[k2++] = i;
    }
    if (a[0] == P[p1] && a[0] != Q[p1] && a[1] == Q[p2] && a[1] != P[p2]) {
      P[p1] = a[0];
      P[p2] = a[1];
    } else if (a[0] == Q[p1] && a[0] != P[p1] && a[1] == P[p2] &&
               a[1] != Q[p2]) {
      P[p1] = a[0];
      P[p2] = a[1];
    } else if (a[1] == P[p1] && a[1] != Q[p1] && a[0] == Q[p2] &&
               a[0] != P[p2]) {
      P[p2] = a[0];
      P[p1] = a[1];
    } else if (a[1] == Q[p1] && a[1] != P[p1] && a[0] == P[p2] &&
               a[0] != Q[p2]) {
      P[p2] = a[0];
      P[p1] = a[1];
    }
    for (long long i = 0; i < n; i++)
      if (i == 0)
        cout << P[i];
      else
        cout << " " << P[i];
    cout << endl;
  }
  return 0;
}
