#include <bits/stdc++.h>
using namespace std;
int p[1005], a[1005], b[1005];
int vis[1005];
int de[3];
int main() {
  int n, tot = 0;
  cin >> n;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) {
    if (a[i] != b[i]) de[tot++] = i;
  }
  if (tot == 1) {
    for (int i = 1; i <= n; i++) vis[a[i]] = 1;
    int tmp;
    for (int i = 1; i <= n; i++) {
      if (vis[i] != 1) {
        tmp = i;
        break;
      }
    }
    for (int i = 1; i <= n; i++) {
      if (i != de[0])
        cout << a[i] << " ";
      else
        cout << tmp << " ";
    }
    cout << endl;
  } else {
    int tmp1 = b[de[0]], tmp2 = a[de[1]], tmp3 = a[de[0]], tmp4 = b[de[1]];
    for (int i = 1; i <= n; i++) {
      if (i == de[0])
        vis[tmp1] = 1;
      else if (i == de[1])
        vis[tmp2] = 1;
      else
        vis[a[i]] = 1;
    }
    int flag = 1;
    for (int i = 1; i <= n; i++)
      if (!vis[i]) {
        flag = 0;
        break;
      }
    if (flag) {
      for (int i = 1; i <= n; i++) {
        if (i == de[0])
          cout << tmp1 << " ";
        else if (i == de[1])
          cout << tmp2 << " ";
        else
          cout << a[i] << " ";
      }
      cout << endl;
    } else {
      for (int i = 1; i <= n; i++) {
        if (i == de[0])
          cout << tmp3 << " ";
        else if (i == de[1])
          cout << tmp4 << " ";
        else
          cout << a[i] << " ";
      }
      cout << endl;
    }
  }
  return 0;
}
