#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        if (N == 2) {
            cout << -1 << endl;
            return;
        }

//        vector<vector<Int>> G(N); // ng edge
        vector<Int> a(N);
        vector<set<Int>> rG(N); // ng edge

        for (int i = 0; i < N; ++i) {
            cin >> a[i];
            a[i]--;
            rG[a[i]].insert(i);
        }

        Int V = N; // 残りの頂点数
        Int ng = -1; //使ってはいけない頂点
        set<Int> rest;
        for (int i = 0; i < N; ++i) rest.insert(i);
        map<Int, set<Int>> mp; //first : 入次数, second : 頂点数

        for (int i = 0; i < N; ++i) {
            mp[rG[i].size()].insert(i);
        }

        vector<Int> path;
        for (; V > 3; V--) {
            Int next = -1;
            if (mp.count(V - 1)) {
                next = *mp[V - 1].begin();
            } else {
                auto pt = rest.begin();
                if (*pt == ng) {
                    pt++;
                }
                next = *pt;
            }

            path.push_back(next);
            rest.erase(next);
            ng = a[next];

            //a[next]が格納されているあれを削除
            Int t = a[next];
            mp[rG[t].size()].erase(t);
            if (mp[rG[t].size()].size() == 0) {
                mp.erase(rG[t].size());
            }

            rG[t].erase(next);
            mp[rG[t].size()].insert(t);
        }

        //nextperm

        vector<Int> v;
        for (auto e : rest) {
            v.push_back(e);
        }

        do {
            bool flag = true;
            if (ng == v[0]) {
                flag = false;
            }
            for (int i = 0; i + 1 < v.size(); ++i) {
                if (a[v[i]] == v[i + 1]) {
                    flag = false;
                }
            }
            if (flag) {
                for (auto e : v) {
                    path.push_back(e);
                }
                break;
            }
        } while (next_permutation(all(v)));

        for (auto e : path) {
            cout << e + 1 << ' ';
        }
        cout << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 18812