#include <bits/stdc++.h>
using namespace std;
int n;
int s[1005];
int us[1005];
int t[1005];
int ut[1005];
int a[1005];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &s[i]);
    us[s[i]]++;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &t[i]);
    ut[t[i]]++;
  }
  int t1 = 0;
  for (int i = 1; i <= n; i++) {
    if (us[i] == 0) {
      t1 = i;
    }
  }
  vector<int> dif;
  for (int i = 0; i < n; i++) {
    a[i] = s[i];
    if (us[s[i]] == 2) {
      dif.push_back(i);
    }
  }
  int tmp;
  for (auto i : dif) {
    tmp = a[i];
    a[i] = t1;
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] != t[j]) cnt++;
    }
    if (cnt == 1) {
      for (int j = 0; j < n; j++) {
        printf("%d%c", a[j], (" \n"[j == n - 1]));
      }
      return 0;
    }
    a[i] = tmp;
  }
}
