#include <bits/stdc++.h>
using namespace std;
int a[2002], b[2002], vis[2002], re[2002], pos[2002], diff[2002];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] == b[i]) {
        re[i] = a[i];
        vis[a[i]]++;
      } else {
        pos[cnt++] = i;
      }
    }
    int cnt2 = 0;
    for (int i = 1; i <= n; i++) {
      if (vis[i] == 0) {
        diff[cnt2++] = i;
      }
    }
    if (cnt == 1) {
      re[pos[0]] = diff[0];
      for (int i = 1; i <= n; i++) {
        printf("%d", re[i]);
        if (i == n)
          printf("\n");
        else
          printf(" ");
      }
    } else {
      int fl = 0;
      for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
          if (i == j) continue;
          re[pos[0]] = diff[i];
          re[pos[1]] = diff[j];
          int s1 = 0, s2 = 0;
          for (int k = 1; k <= n; k++) {
            if (re[k] != a[k]) s1++;
            if (re[k] != b[k]) s2++;
          }
          if (s1 == 1 && s2 == 1) {
            fl = 1;
            break;
          }
        }
        if (fl) break;
      }
      for (int i = 1; i <= n; i++) {
        printf("%d", re[i]);
        if (i == n)
          printf("\n");
        else
          printf(" ");
      }
    }
  }
  return 0;
}
