3
2 1 1
 6
6 2 6 2 4 2
 2
1 2
 8
2 1 2 2 6 5 6 6
 18
2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18
 7
1 2 3 4 5 6 7
 7
4 3 2 6 3 5 2
 7
7 5 3 1 2 1 5
 7
1 6 4 4 5 6 7

1
2 2 1  0
6 2 6 2 4 2  1 
1 1 
 2 
2 2 2 2 6 2 6 6 
 5 
2 3 4 5 11 7 8 9 10 11 11 11 14 15 11 17 18 11 
 6 
1 1 1 1 1 1 1 
 1
4 3 3 6 3 5 2  1
7 5 3 1 3 1 5  4 
1 6 4 1 1 1 1 

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().run(in, out);
        out.close();
    }

    int N;
    List<Integer>[] adj;
    void run(FastScanner in, PrintWriter out) {

        N = in.nextInt();

        LinkedList<Integer> freeSet = new LinkedList<>();
        int[] a = new int[N+1];
        UnionFind uf = new UnionFind(N);
        int count = 0;
        for (int u = 1; u <= N; u++) {
            int v = in.nextInt();
            a[u] = v;


            if (uf.findParent(u) != uf.findParent(v)) {
                uf.merge(u, v);
                continue;
            }

            count++;
            // already same union
            if (!freeSet.isEmpty()) {
                int top = freeSet.pollFirst();
                a[top] = u;
                uf.merge(top, u);
            }
            freeSet.offer(u);
        }

        for (int i = 1; i <= N; i++) {
            out.print(a[i] + " ");
        }
        out.println();



    }

    class UnionFind {
        int[] parent;
        int[] rank;
        UnionFind(int N) {
            parent = new int[N+1];
            rank = new int[N+1];
            for (int i = 1; i <= N; i++) {
                parent[i] = i;
            }
        }

        int findParent(int x) {
            int init = x;
            while (x != parent[x]) x = parent[x];
            return parent[init] = x;
        }

        void merge(int x, int y) {
            int px = findParent(x);
            int py = findParent(y);
            if (px == py) return;

            int rx = rank[px];
            int ry = rank[py];
            if (rx <= ry) {
                parent[px] = py;
                if (rx == ry) rank[py]++;
            } else {
                parent[py] = px;
            }
        }

    }





    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}
