#include <bits/stdc++.h>
using namespace std;
int n;
int a[1005];
int b[1005];
int vis[1005];
int ia, ia1 = -1, ia2 = -1, ca, cnt;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    vis[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) ca = i;
    if (vis[i] == 2) ia = i;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == ia && ia1 == -1)
      ia1 = i;
    else if (a[i] == ia)
      ia2 = i;
  }
  a[ia1] = ca;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] != a[i]) cnt++;
  }
  if (cnt != 1) {
    a[ia1] = ia;
    a[ia2] = ca;
  }
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  return 0;
}
