#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int a[2005], b[2005];
  while (~scanf("%d", &n)) {
    int c[1005], d[1005];
    map<int, int> M;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
    int k = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] == b[i]) {
        c[i] = a[i];
        M[a[i]]++;
      } else {
        d[k++] = i;
      }
    }
    if (k == 1) {
      int s;
      for (int i = 1; i <= n; i++) {
        if (M[i] == 0) s = i;
      }
      c[d[0]] = s;
    } else {
      int t1 = d[0];
      int t2 = d[1];
      if (M[a[t1]] == 0 && M[b[t2]] == 0) {
        c[t1] = a[t1];
        c[t2] = b[t2];
      } else {
        c[t1] = b[t1];
        c[t2] = a[t2];
      }
    }
    for (int i = 1; i <= n; i++) {
      if (i == 1)
        printf("%d", c[i]);
      else
        printf(" %d", c[i]);
    }
    printf("\n");
  }
  return 0;
}
