#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
using namespace std;
int a[1111], b[1111], res[1111];
bool buc[1111];
int main() {
  int n;
  scanf("%d", &n);
  int cnt = 0;
  for (int i = (int)(0); i < (int)(n); ++i) scanf("%d", &a[i]);
  for (int i = (int)(0); i < (int)(n); ++i) scanf("%d", &b[i]);
  for (int i = (int)(0); i < (int)(n); ++i)
    if (a[i] != b[i]) cnt++;
  for (int i = (int)(0); i < (int)(n); ++i) {
    if (a[i] == b[i] && !buc[a[i]]) {
      buc[a[i]] = true;
      res[i] = a[i];
    } else
      res[i] = -1;
  }
  if (cnt == 1) {
    for (int i = (int)(0); i < (int)(n); ++i) {
      if (a[i] != b[i]) {
        for (int j = 1; j <= n; j++) {
          if (j != a[i] && j != b[i] && !buc[j]) {
            res[i] = j;
            buc[j] = true;
            break;
          }
        }
      }
    }
  } else {
    int first = -1, second = -1;
    for (int i = (int)(0); i < (int)(n); ++i) {
      if (a[i] != b[i]) {
        if (first == -1)
          first = i;
        else
          second = i;
      }
    }
    if (!buc[a[first]] && !buc[b[second]]) {
      res[first] = a[first];
      res[second] = b[second];
    } else if (!buc[a[second]] && !buc[b[first]]) {
      res[second] = a[second];
      res[first] = b[first];
    }
  }
  for (int i = (int)(0); i < (int)(n); ++i) printf("%d ", res[i]);
  cout << endl;
  return 0;
}
