#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    if(N==2) dame;
    vector<ll> ans(N,0);
    priority_queue<ll,vector<ll>,greater<ll>> qu;
    reps(i,1,N) qu.emplace(i+1);
    ans[0]=1;
    reps(i,1,N-1){
        if(A[ans[i-1]-1]==qu.top()){
            ll x=qu.top(); qu.pop();
            ans[i]=qu.top(); qu.pop();
            qu.emplace(x);
        }
        else{
            ans[i]=qu.top(); qu.pop();
        }
    }
    ans[N-1]=qu.top();
    ll yy=ans[N-1];
    ll here=N-1;
    while(here!=0 and A[ans[here-1]-1]==ans[N-1]){
        --here;
    }
    priority_queue<ll,vector<ll>,greater<ll>> qu2;
    reps(i,here,N-1) qu2.emplace(ans[i]);
    ans[here]=yy;
    reps(i,here+1,N-1){
        if(A[ans[i-1]-1]==qu2.top()){
            ll x=qu2.top(); qu2.pop();
            ans[i]=qu2.top(); qu2.pop();
            qu2.emplace(x);
        }
        else{
            ans[i]=qu2.top(); qu2.pop();
        }
    }
    if(!qu2.empty()) ans[N-1]=qu2.top();
    ll x1=ans[N-3],x2=ans[N-2],x3=ans[N-1];

    vector<ll> r={x1,x2,x3};
    SORT(r);
    do{
        ans[N-3]=r[0],ans[N-2]=r[1],ans[N-1]=r[2];
        bool ok=true;
        reps(i,1,N){
            if(A[ans[i-1]-1]==ans[i]) ok=false;
        }
        if(ok) break;
    }while(next_permutation(r.begin(),r.end()));

    rep(i,N){
        cout<< ans[i] <<" ";
    }
    cout<<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------
