#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
const int _ML = 30;
const char _inpf[] = "";
const char _outf[] = "";
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
  _out << _p.x << ' ' << _p.y;
  return _out;
}
template <typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
  _in >> _p.x >> _p.y;
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
  if (_v.empty()) return _out;
  _out << _v.front();
  for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out << ' ' << *_it;
  return _out;
}
template <typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
  for (auto &_i : _v) _in >> _i;
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const set<T> &_s) {
  if (_s.empty()) return _out;
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it;
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {
  if (_s.empty()) return _out;
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it;
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {
  if (_s.empty()) return _out;
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it;
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {
  if (_s.empty()) return _out;
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it;
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {
  if (_m.empty()) return _out;
  _out << '(' << _m.begin()->x << ": " << _m.begin()->y << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it)
    _out << ", (" << _it->x << ": " << _it->y << ')';
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) {
  if (_m.empty()) return _out;
  _out << '(' << _m.begin()->x << ": " << _m.begin()->y << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it)
    _out << ", (" << _it->x << ": " << _it->y << ')';
  return _out;
}
inline void mainFunction(void) {
  int n;
  cin >> n;
  vector<int> v(n), w(n);
  cin >> v >> w;
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    if (v[i] != w[i]) {
      a.push_back(i);
    }
  }
  if ((int)(a).size() == 0) {
    map<int, int> cnt;
    for (int i : v) ++cnt[i];
    int zr = -1, tw = -1;
    for (int i = 1; i <= n; ++i) {
      if (cnt[i] == 0) zr = i;
      if (cnt[i] == 2) tw = i;
    }
    *find((v).begin(), (v).end(), tw) = zr;
    cout << v << '\n';
  } else if ((int)(a).size() == 1) {
    map<int, int> cnt;
    for (int i : v) ++cnt[i];
    int zr = -1, tw = -1;
    for (int i = 1; i <= n; ++i) {
      if (cnt[i] == 0) zr = i;
      if (cnt[i] == 2) tw = i;
    }
    *find((v).begin(), (v).end(), tw) = zr;
    int cc = 0;
    for (int i = 0; i < n; ++i) cc += (v[i] == w[i]);
    if (cc == n - 1) {
      cout << v << '\n';
      return;
    }
    *find((v).begin(), (v).end(), tw) = zr;
    *find((v).begin(), (v).end(), zr) = tw;
    cout << v << '\n';
    return;
  } else {
    int mem = v[a[0]];
    v[a[0]] = w[a[0]];
    set<int> st((v).begin(), (v).end());
    if ((int)(st).size() == n) {
      cout << v << '\n';
      return;
    }
    v[a[0]] = mem;
    v[a[1]] = w[a[1]];
    cout << v << '\n';
  }
}
int main() {
  if (_inpf[0] != '\0') assert(freopen(_inpf, "r", stdin) != nullptr);
  if (_outf[0] != '\0') assert(freopen(_outf, "w", stdout) != nullptr);
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << setprecision(20);
  mainFunction();
}
