#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n], b[n];
  int fa, fb, la, lb;
  bool showed[n + 1];
  memset(showed, 0, sizeof showed);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int c = 0;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (a[i] == b[i])
      showed[a[i]] = true;
    else {
      if (c) {
        la = a[i];
        lb = b[i];
      } else {
        fa = a[i];
        fb = b[i];
      }
      c++;
    }
  }
  int aux = 0;
  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    if (a[i] == b[i]) {
      cout << a[i];
    } else {
      if (c == 1) {
        for (int j = 1; j <= n; j++) {
          if (!showed[j]) {
            cout << j;
            break;
          }
        }
      } else {
        if (aux)
          cout << aux;
        else if (!showed[fa] && !showed[lb]) {
          cout << fa;
          aux = lb;
        } else {
          cout << fb;
          aux = la;
        }
      }
    }
  }
  cout << "\n";
  return 0;
}
