#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(0);
  long long int i, j, k, n, m, sum, l, r;
  long long int aa[10000];
  long long int bb[10000];
  long long int pp[10000];
  long long int yoyo[1002];
  cin >> n;
  for (i = 0; i < 1002; i++) {
    yoyo[i] = 0;
  }
  for (i = 0; i < n; i++) {
    cin >> aa[i];
  }
  for (i = 0; i < n; i++) {
    cin >> bb[i];
  }
  int count = 0;
  for (i = 0; i < n; i++) {
    if (aa[i] != bb[i]) count = count + 1;
  }
  if (count == 0) {
    for (i = 0; i < n; i++) {
      if (i == 0) {
        if (aa[i] == n)
          pp[i] = aa[i] - 1;
        else
          pp[i] = n;
      } else {
        pp[i] = aa[i];
      }
    }
  } else if (count == 1) {
    for (i = 0; i < n; i++) {
      yoyo[aa[i]] = yoyo[aa[i]] + 1;
      yoyo[bb[i]] = yoyo[bb[i]] + 1;
    }
    int uuk;
    for (i = 0; i < n; i++) {
      if (aa[i] != bb[i])
        uuk = i;
      else
        pp[i] = aa[i];
    }
    for (i = 1; i <= n; i++) {
      if (yoyo[i] == 0) pp[uuk] = i;
    }
  } else {
    int ss = 0;
    for (i = 0; i < n; i++) {
      if (aa[i] == bb[i]) {
        pp[i] = aa[i];
      } else {
        if (ss == 0) {
          pp[i] = aa[i];
          ss = ss + 1;
        } else {
          pp[i] = bb[i];
        }
      }
    }
    for (i = 0; i < 1002; i++) {
      yoyo[pp[i]] = yoyo[pp[i]] + 1;
    }
    int lmn = 0;
    for (i = 1; i <= n; i++) {
      if (yoyo[i] == 0) {
        lmn = 1;
        break;
      }
    }
    if (lmn == 1) {
      ss = 0;
      for (i = 0; i < n; i++) {
        if (aa[i] == bb[i]) {
          pp[i] = aa[i];
        } else {
          if (ss == 0) {
            pp[i] = bb[i];
            ss = ss + 1;
          } else {
            pp[i] = aa[i];
          }
        }
      }
      for (i = 0; i < 1002; i++) {
        yoyo[i] = 0;
      }
      for (i = 0; i < n; i++) {
        yoyo[pp[i]] = yoyo[pp[i]] + 1;
      }
      int lmn2 = 0;
      for (i = 1; i <= n; i++) {
        if (yoyo[i] == 0) {
          lmn2 = 1;
          break;
        }
      }
      if (lmn2 == 1) {
        for (i = 0; i < 1002; i++) {
          yoyo[i] = 0;
        }
        for (i = 0; i < n; i++) {
          yoyo[aa[i]] = yoyo[aa[i]] + 1;
          yoyo[bb[i]] = yoyo[bb[i]] + 1;
        }
        int hjk, lkj;
        int mnb = 0;
        for (i = 1; i <= n; i++) {
          if (yoyo[i] == 0) {
            if (mnb == 0) {
              hjk = i;
              mnb = mnb + 1;
            } else
              lkj = i;
          }
        }
        mnb = 0;
        for (i = 0; i < n; i++) {
          if (aa[i] == bb[i])
            pp[i] = aa[i];
          else {
            if (mnb == 0) {
              pp[i] = hjk;
              mnb = mnb + 1;
            } else
              pp[i] = lkj;
          }
        }
      }
    }
  }
  for (i = 0; i < n; i++) {
    cout << pp[i] << " ";
  }
  return 0;
}
