#include <bits/stdc++.h>
using namespace std;
int maxarr(vector<int> &arr);
int minarr(vector<int> &arr);
long long modulo(long long base, long long exponent, long long modulus);
long long choose(long long n, long long k);
bool isprime(long long n);
long long inverse(long long a, long long m);
long long fastmult(long long a, long long b, long long c);
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  set<int> same;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  ;
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  ;
  vector<int> place;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      same.insert(a[i]);
      p[i] = a[i];
    } else
      place.push_back(i);
  }
  vector<int> temp;
  for (int i = 1; i < n + 1; i++) {
    if (!same.count(i)) temp.push_back(i);
  }
  vector<int> p1 = p;
  vector<int> p2 = p;
  vector<int> ans;
  int counta = 0, countb = 0;
  if (place.size() == 2) {
    p1[place[0]] = temp[0];
    p1[place[1]] = temp[1];
    p2[place[0]] = temp[1];
    p2[place[1]] = temp[0];
    counta = 0;
    countb = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] != p1[i]) counta++;
      if (b[i] != p1[i]) countb++;
    }
    if (counta == 1 && countb == 1)
      ans = p1;
    else
      ans = p2;
  } else {
    p1[place[0]] = temp[0];
    ans = p1;
  }
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
  return 0;
}
int maxarr(vector<int> &arr) {
  int maxi = INT_MIN;
  for (int i = 0; i < arr.size(); i++) maxi = max(arr[i], maxi);
  return maxi;
}
int minarr(vector<int> &arr) {
  int mini = INT_MAX;
  for (int i = 0; i < arr.size(); i++) mini = min(arr[i], mini);
  return mini;
}
long long modulo(long long base, long long exponent, long long modulus) {
  if (modulus == 1) return 0;
  long long result = 1;
  base = base % modulus;
  while (exponent > 0) {
    if (exponent % 2 == 1) {
      result = (result * base) % modulus;
    }
    exponent = exponent >> 1;
    base = (base * base) % modulus;
  }
  return result;
}
long long choose(long long n, long long k) {
  if (k == 0) return 1;
  return (n * choose(n - 1, k - 1)) / k;
}
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
void EE(long long a, long long b, long long &co1, long long &co2) {
  if (a % b == 0) {
    co1 = 0;
    co2 = 1;
    return;
  }
  EE(b, a % b, co1, co2);
  long long temp = co1;
  co1 = co2;
  co2 = temp - co2 * (a / b);
}
long long inverse(long long a, long long m) {
  long long x, y;
  EE(a, m, x, y);
  if (x < 0) x += m;
  return x;
}
long long fastmult(long long a, long long b, long long c) {
  if (b == 0) return 0;
  long long res = fastmult(a, b >> 1, c);
  res = (res + res) % c;
  if (b % 2 == 1) {
    res = (res + a) % c;
  }
  return res;
}
