#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int f[n + 1];
  unordered_map<int, int> getsGiftFrom;
  for (int i = 1; i <= n; i++) {
    cin >> f[i];
    if (f[i]) {
      getsGiftFrom[f[i]] = i;
    }
  }
  vector<int> fullEmpty, noSending, noRecieving;
  for (int i = 1; i <= n; i++) {
    auto it = getsGiftFrom.find(i);
    if (f[i] && it != getsGiftFrom.end()) {
      continue;
    } else if (!f[i] && it == getsGiftFrom.end()) {
      fullEmpty.push_back(i);
    } else if (!f[i]) {
      noSending.push_back(i);
    } else if (it == getsGiftFrom.end()) {
      noRecieving.push_back(i);
    }
  }
  while (noSending.size() >= 2) {
    f[noSending.back()] = noRecieving.back();
    noRecieving.pop_back();
    noSending.pop_back();
  }
  if (fullEmpty.size() == 1) {
    f[noSending.back()] = fullEmpty.back();
    f[fullEmpty.back()] = noRecieving.back();
  } else if (noSending.size()) {
    f[noSending.back()] = noRecieving.back();
  }
  if (fullEmpty.size() >= 2) {
    for (int i = 1; i < fullEmpty.size(); i++) {
      f[fullEmpty[i - 1]] = fullEmpty[i];
    }
    f[fullEmpty.back()] = fullEmpty[0];
  }
  for (int i = 1; i <= n; i++) {
    cout << f[i] << " ";
  }
  cout << endl;
  return 0;
}
