#include <bits/stdc++.h>
using namespace std;
int n, a[2001], b[2001], ans[2001], l[2001];
int main() {
  cin >> n;
  int r;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  int san = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] == b[i]) l[a[i]] = 1, ans[i] = a[i], san++;
  if (san == n - 1) {
    int r = 0;
    for (int i = 1; i <= n; i++)
      if (l[i] == 0) {
        r = i;
        break;
      }
    for (int i = 1; i <= n; i++) cout << ((ans[i] == 0) ? r : ans[i]) << " ";
    cout << endl;
  } else {
    int x = -1, y = -1;
    for (int i = 1; i <= n; i++) {
      if (l[i] == 0) {
        if (x == -1)
          x = i;
        else
          y = i;
      }
    }
    for (int i = 1; i <= n; i++) {
      if (a[i] != b[i]) {
        for (int j = 1; j <= n; j++) {
          if (i != j && a[j] != b[j]) {
            ans[i] = x;
            ans[j] = y;
            int h1 = 0, h2 = 0;
            for (int k = 1; k <= n; k++) {
              h1 += (ans[k] == a[k]);
              h2 += (ans[k] == b[k]);
            }
            if (h1 == n - 1 && h2 == n - 1) {
              for (int k = 1; k <= n; k++) cout << ans[k] << " ";
              return 0;
            }
          }
        }
      }
    }
  }
  return 0;
}
