#include <bits/stdc++.h>
using namespace std;
const int nMax = 1005;
int n;
vector<int> a(nMax, 0), b(nMax, 0), check(nMax, 0);
int x, y;
bool test() {
  int dem = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] != b[i]) ++dem;
  }
  return (dem == 1);
}
void print() {
  for (int i = 0; i < n; ++i) cout << a[i] << " ";
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    check[a[i]]++;
  }
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int i = 1; i <= n; ++i)
    if (check[i] == 0)
      y = i;
    else if (check[i] == 2)
      x = i;
  for (int i = 0; i < n; ++i)
    if (a[i] == x) {
      a[i] = y;
      if (test()) {
        print();
        return 0;
      } else {
        a[i] = x;
        break;
      }
    }
  for (int i = n - 1; i >= 0; --i) {
    if (a[i] == x) {
      a[i] = y;
      print();
      return 0;
    }
  }
}
