#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long N = 2000 + 10;
const long long IM = 1e15 + 37;
const long double PI = 3.1415926535897932384;
inline void PP(long long n) { cout << n << " "; }
void PV(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << "\n";
}
void PVV(vector<pair<long long, long long> > v) {
  for (long long i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << "\n";
}
void PA(long long v[], long long n, long long x = 0) {
  for (long long i = x; i < n + x; i++) cout << v[i] << ' ';
  cout << "\n";
}
void IN(long long a[], long long n, long long x = 0) {
  for (long long i = x; i < n + x; i++) cin >> a[i];
}
inline void op() {}
signed main() {
  op();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long a[n + 10], b[n + 10];
  IN(a, n, 1);
  IN(b, n, 1);
  vector<long long> v;
  map<long long, long long> ma, mb;
  for (long long i = 1; i <= n; i++) {
    if (a[i] != b[i]) v.push_back(i);
    ma[a[i]]++;
    mb[b[i]]++;
  }
  long long u = -1, k = -1;
  long long y = -1;
  for (long long i = 1; i <= n; i++) {
    if (!ma[i]) {
      u = i;
    }
    if (ma[i] > 1) y = i;
  }
  for (long long i = 1; i <= n; i++) {
    if (a[i] == y) {
      a[i] = u;
      long long c = 0;
      bool ck = 0;
      for (auto it : v) {
        if (a[it] != b[it]) c++;
        if (it == i) ck = 1;
      }
      if (c == 1 && ck) {
        PA(a, n, 1);
        return 0;
      }
      a[i] = y;
    }
  }
  return 0;
}
