#include <bits/stdc++.h>
using namespace std;
map<string, long long> m1;
map<string, long long> m2;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, i, j;
  cin >> n;
  long long a[n + 1];
  for (i = 1; i <= n; i++) cin >> a[i];
  long long b[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> b[i];
  }
  long long p = 0;
  for (i = 1; i <= n; i++) {
    if (a[i] != b[i]) p++;
  }
  long long c[n + 1];
  for (i = 1; i <= n; i++) {
    if (a[i] == b[i])
      continue;
    else if (p > 1) {
      for (j = 1; j <= n; j++) c[j] = a[j];
      c[i] = b[i];
      long long x = 0;
      set<long long> s;
      s.clear();
      for (j = 1; j <= n; j++) {
        s.insert(c[j]);
      }
      for (j = 1; j <= n; j++) {
        if (c[j] != b[j]) x++;
      }
      if ((x == 1) && (s.size() == n)) break;
    } else {
      long long f;
      long long g[1005] = {0};
      for (j = 1; j <= n; j++) {
        if (a[j] == b[j]) {
          c[j] = a[j];
          g[a[j]] = 1;
        } else
          f = j;
      }
      for (j = 1; j <= n; j++) {
        if (!g[j]) c[f] = j;
      }
    }
  }
  for (i = 1; i <= n; i++) cout << c[i] << " ";
  return 0;
}
