#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }



template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}



int N;
vector<int> p;
vector<set<int>> ip;

bool check(const vector<int> &res) {
    for (int i = 0; i + 1 < res.size(); ++i) {
        if (res[i+1] == p[res[i]]) return false;
    }
    return true;
}

void last(vector<int> &res, vector<int> &rem) {
    do {
        if (res.size() > 0 && rem[0] == p[res.back()]) continue;
        if (check(rem)) {
            for (int i = 0; i < res.size(); ++i) cout << res[i] + 1 << " ";
            for (int i = 0; i < rem.size(); ++i) cout << rem[i] + 1 << " ";
            cout << endl;
            return;
        }
    } while (next_permutation(rem.begin(), rem.end()));

    cout << -1 << endl;
    return;
}

const int NOKORI = 5;
void solve() {
    if (N <= NOKORI) {
        vector<int> res, rem(N);
        for (int i = 0; i < N; ++i) rem[i] = i;
        last(res, rem);
        return;
    }

    vector<int> res;
    set<int> rem;
    for (int i = 0; i < N; ++i) rem.insert(i);
    while (N - (int)res.size() > NOKORI) {
        // COUT("-------------");
         
        int dame = -1;
        if (res.size() > 0) dame = p[res.back()];

        // とりあえず Greedy に
        int ne = -1;
        for (auto it : rem) {
            if (it == dame) continue;
            ne = it;
            break;
        }

        /*
        COUT(ne);
        COUT(p[ne]);
        COUT(ip[p[ne]].size());
        */

        // ne を選んでしまうと詰むときは取り替える
        if (ip[p[ne]].size() + res.size() == N-1) {
            ne = p[ne];
        }

        // ne を選ぶ
        res.push_back(ne);
        rem.erase(ne);
        ip[p[ne]].erase(ne);

        /*
        COUT(ne);
        COUT(ip);
        COUT(res);
        */
    }
    vector<int> vrem;
    for (int i = 0; i < N; ++i) if (rem.count(i)) vrem.push_back(i);
    last(res, vrem);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> N) {
        p.resize(N);
        ip.assign(N, set<int>());
        for (int i = 0; i < N; ++i) {
            cin >> p[i];
            --p[i];
            ip[p[i]].insert(i);
        }
        solve();
    }
}


















Measured memory_bytes: 15360