#include <bits/stdc++.h>
using namespace std;
int n;
int ara[1010], ar[1010];
int cnt[1010];
bool check() {
  int f = 0, c = 0;
  for (int i = 1; i <= n; i++) {
    if (ara[i] == ar[i]) c++;
    if (cnt[ar[i]] != 1) {
      f = 1;
      break;
    }
  }
  if (c == n - 1 && f == 0) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  int milenai = 0;
  for (int i = 1; i <= n; i++) cin >> ara[i];
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
    cnt[ar[i]]++;
  }
  int flag = 0;
  for (int i = 1; i <= n; i++) {
    if (ar[i] != ara[i]) milenai++;
  }
  for (int i = 1; i <= n; i++) {
    if (ar[i] != ara[i]) {
      cnt[ara[i]]++;
      cnt[ar[i]]--;
      int tem = ar[i];
      ar[i] = ara[i];
      if (check()) {
        for (int i = 1; i <= n; i++) {
          if (i == 1)
            cout << ar[i];
          else
            cout << " " << ar[i];
        }
        cout << endl;
        flag = 1;
      }
      cnt[ara[i]]--;
      cnt[tem]++;
      ar[i] = tem;
    }
    if (flag == 1) break;
  }
  if (flag == 0 && milenai == 1) {
    int paice;
    for (int i = 1; i <= n; i++) {
      if (cnt[i] == 0) {
        paice = i;
        break;
      }
    }
    for (int i = 1; i <= n; i++) {
      if (ar[i] != ara[i]) {
        if (i == 1)
          cout << paice;
        else
          cout << " " << paice;
      } else {
        if (i == 1)
          cout << ar[i];
        else
          cout << " " << ar[i];
      }
    }
    cout << endl;
  }
  return 0;
}
