#include <string>
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <queue>
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <ctime> 
#include <cstring> 
#include <tuple>

using namespace std;

int point_to[110000];

struct comp {
    bool operator() (const int a, const int ot) const {
        return pair<int,int>(point_to[a], a) > pair<int,int>(point_to[ot], ot);
    }
};

int n;
int forb[110000];
int p[110000];
set<int, comp> pt;
set<int> av;
vector<int> avv;

bool go(int cur, int rem, int proi) {
    if (rem == 0) return true;

    for (int i = 0; i < rem; i++) if (avv[i] != proi) {
        p[cur] = avv[i];
        avv.erase(avv.begin()+i);
        if (go(cur+1, rem-1, forb[p[cur]])) {
            return true;
        }
        avv.insert(avv.begin()+i, p[cur]);
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> forb[i];
        forb[i]--;
        point_to[forb[i]]++;
        av.insert(i);
    }

    for (int i = 0; i < n; i++) {
        pt.insert(i);
    }

    int proi = -1;
    int st = 0;

    for (int i = 0; i < n-10; i++) {
        int big_point = *pt.begin();
        if (point_to[big_point] == (n-i)-1) {
            p[i] = big_point;
        }
        else {
            p[i] = *av.begin();
            if (p[i] == proi) p[i] = *(++av.begin());
        }

        av.erase(p[i]);
        proi = forb[p[i]];
        pt.erase(p[i]);
        
        if (av.count(proi)) {
            pt.erase(proi);
            point_to[proi]--;
            pt.insert(proi);
        }

        st++;
    }

    for (int x : av) avv.push_back(x);
    if (go(st, n-st, proi)) {
        for (int i = 0; i < n; i++) {
            cout << p[i]+1;
            if (i != n-1) cout << ' ';
        }
        cout << endl;
    }
    else cout << -1 << endl;


}


