#include <bits/stdc++.h>
const int N = 1e3 + 100;
int n;
int a[N], b[N];
void init() {
  std::cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
  }
}
bool check(int c[]) {
  int cntDiff[2] = {0, 0};
  for (int i = 1; i <= n; i++) {
    cntDiff[0] += (a[i] != c[i]);
    cntDiff[1] += (b[i] != c[i]);
  }
  return cntDiff[0] == 1 && cntDiff[1] == 1;
}
void work() {
  std::map<int, int> cnt;
  for (int i = 1; i <= n; i++) {
    cnt[a[i]]++;
  }
  int twice, zero;
  for (int i = 1; i <= n; i++) {
    if (cnt[i] == 2) {
      twice = i;
    }
    if (cnt[i] == 0) {
      zero = i;
    }
  }
  static int c[N];
  for (int i = 1; i <= n; i++) {
    if (a[i] == twice) {
      for (int j = 1; j <= n; j++) {
        c[j] = a[j];
      }
      c[i] = zero;
      if (check(c)) {
        for (int j = 1; j <= n; j++) {
          printf("%d%c", c[j], " \n"[j == n]);
        }
        return;
      }
    }
  }
}
int main() {
  init();
  work();
  return 0;
}
