#include <bits/stdc++.h>
using namespace std;
long long bin_pow(long long x, long long e) {
  long long k;
  if (e == 0) return 1;
  if (e % 2)
    return bin_pow(x, e - 1) * x;
  else {
    k = bin_pow(x, e / 2);
    return k * k;
  }
}
set<int> g;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, counter = 0, counter2 = 0, counter3 = 0;
  cin >> n;
  int a[2222], b[2222], p[2222], used[2222];
  int index1, index2, nused1, nused2;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    used[i + 1] = 0;
  }
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      p[i] = a[i];
      used[a[i]] = 1;
      counter++;
    } else {
      if (!counter2) {
        index1 = i;
        counter2++;
      } else
        index2 = i;
    }
  }
  if (counter == n - 1) {
    for (int i = 0; i < n; i++) {
      if (used[i + 1] == 0) p[index1] = i + 1;
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (used[i + 1] == 0) {
        if (!counter3) {
          nused1 = i + 1;
          counter3++;
        } else
          nused2 = i + 1;
      }
    }
    if (a[index1] == nused1 && b[index2] == nused2) {
      p[index1] = nused1;
      p[index2] = nused2;
    } else if (a[index1] == nused2 && b[index2] == nused1) {
      p[index1] = nused2;
      p[index2] = nused1;
    } else if (a[index2] == nused2 && b[index1] == nused1) {
      p[index1] = nused1;
      p[index2] = nused2;
    } else if (a[index2] == nused1 && b[index1] == nused2) {
      p[index1] = nused2;
      p[index2] = nused1;
    }
  }
  for (int i = 0; i < n; i++) cout << p[i] << " ";
  return 0;
}
