#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline long long toll(string s) {
  long long v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
int p[100002], a[100002], b[100002];
int seen[100002];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  int missed = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      missed++;
    } else {
      p[i] = a[i];
      seen[p[i]] = 1;
    }
  }
  if (missed == 1) {
    for (int i = 1; i <= n; i++) {
      if (!seen[i]) {
        missed = i;
        break;
      }
    }
    for (int i = 0; i < n; i++) {
      if (p[i]) {
        cout << p[i] << " ";
      } else {
        cout << missed << " ";
      }
    }
  } else {
    int f = 0;
    int s = 0;
    for (int i = 1; i <= n; i++) {
      if (!seen[i]) {
        if (f) {
          s = i;
        } else
          f = i;
      }
    }
    int fi = -1, si = -1;
    for (int i = 0; i < n; i++) {
      if (!p[i]) {
        if (fi == -1) {
          fi = i;
        } else
          si = i;
      }
    }
    if ((f == a[fi] || f == b[fi]) && (s == a[si] || s == b[si])) {
      p[fi] = f;
      p[si] = s;
    } else {
      p[fi] = s;
      p[si] = f;
    }
    for (int i = 0; i < n; i++) {
      cout << p[i] << " ";
    }
  }
  return 0;
}
