#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[1005], b[1005];
  while (scanf("%d", &n) != EOF) {
    int c[1005], d[1005];
    bool visit[1005] = {false};
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int j = 1; j <= n; j++) scanf("%d", &b[j]);
    int k = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] == b[i]) {
        c[i] = a[i];
        visit[a[i]] = true;
      } else {
        d[k++] = i;
      }
    }
    if (k == 1) {
      int s;
      for (int i = 1; i <= n; i++) {
        if (visit[i] == 0) s = i;
      }
      c[d[0]] = s;
    } else {
      int t1 = d[0];
      int t2 = d[1];
      if (!visit[a[t1]] && !visit[b[t2]]) {
        c[t1] = a[t1];
        c[t2] = b[t2];
      } else {
        c[t1] = b[t1];
        c[t2] = a[t2];
      }
    }
    for (int i = 1; i <= n; i++) {
      cout << c[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
