#include <bits/stdc++.h>
using namespace std;
const int module = 1e7 + 7;
const int N = 2e5 + 7;
int n, m, a[N], b[N], f1[N], f2[N], s1, s2, stk[N], f[N], p[N];
bool cmp(int a, int b) { return a > b; }
void nhap() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
  }
  for (int i = 1; i <= n; i++) {
    f1[a[i]]++;
    f2[b[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (f1[i] == 0) {
      s1 = i;
    }
    if (f2[i] == 0) {
      s2 = i;
    }
  }
}
bool check(int x) {
  int dem = 0;
  for (int i = 1; i <= n; i++) {
    if (i == x) {
      continue;
    }
    if (a[i] == b[i]) {
      dem++;
    }
  }
  if (dem == n - 1) {
    return true;
  } else {
    return false;
  }
}
void solve() {
  int j = 1;
  a[0] = -1;
  for (int i = 1; i <= n; i++) {
    if (f1[a[i]] == 2) {
      if ((s1 == b[i]) || (check(i) == true)) {
        a[i] = s1;
        for (int k = 1; k <= n; k++) {
          cout << a[k] << " ";
        }
        return;
      }
    }
  }
}
int main() {
  nhap();
  solve();
}
