#include <bits/stdc++.h>
using namespace std;
int q[1005];
int w[1005];
int p[1005];
int vis[1005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &q[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  int a = 0;
  int b = 0;
  int k = 0;
  for (int i = 1; i <= n; i++) {
    if (q[i] == w[i]) {
      p[i] = q[i];
      vis[q[i]] = 1;
    } else {
      k++;
      p[i] = -1;
      if (k == 1)
        a = i;
      else
        b = i;
    }
  }
  int c, d;
  int mark = 0;
  if (k == 2) {
    for (int i = 1; i <= n; i++) {
      if (vis[i] == 0) {
        mark++;
        if (mark == 1)
          c = i;
        else
          d = i;
      }
    }
    p[a] = c;
    p[b] = d;
    bool f = true;
    int cha = 0;
    for (int i = 1; i <= n; i++) {
      if (q[i] != p[i]) cha++;
    }
    if (cha != 1) f = false;
    cha = 0;
    for (int i = 1; i <= n; i++) {
      if (w[i] != p[i]) cha++;
    }
    if (cha != 1) f = false;
    if (!f) p[a] = d, p[b] = c;
  } else {
    for (int i = 1; i <= n; i++) {
      if (vis[i] == 0) {
        p[a] = i;
        break;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i != n)
      printf("%d ", p[i]);
    else
      printf("%d\n", p[i]);
  }
  return 0;
}
