#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
class Task {
 public:
  void solve(istream& in, ostream& out) {
    int N;
    in >> N;
    vector<int> f(N), deg_in(N, 0);
    vector<bool> flag(N, false);
    for (int i = (0); i < (N); ++i) {
      in >> f[i], f[i]--;
      if (f[i] != -1) {
        deg_in[f[i]] = 1;
        flag[i] = true;
      }
    }
    for (int i = (0); i < (N); ++i) {
      if (deg_in[i] or f[i] == -1) continue;
      int u = i;
      while (f[u] != i and f[u] != -1) u = f[u];
      if (f[u] == -1) f[u] = i;
    }
    vector<int> vec;
    for (int i = (0); i < (N); ++i)
      if (f[i] == -1) vec.push_back(i);
    int m = (int)(vec).size();
    if (m == 1) {
      int id = -1;
      for (int i = (0); i < (N); ++i)
        if (not flag[i] and f[i] != -1) {
          id = i;
          break;
        }
      f[vec.front()] = f[id];
      f[id] = vec.front();
    } else
      for (int i = (0); i < (m); ++i) f[vec[i]] = vec[(i + 1) % m];
    for (auto a : f) out << a + 1 << ' ';
    out << '\n';
  }
};
int main() {
  istream& in(cin);
  ostream& out(cout);
  ios_base::sync_with_stdio(false);
  in.tie(nullptr), out.tie(nullptr);
  Task solver;
  solver.solve(in, out);
  return 0;
}
