#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2 vector<vec>
#define vecll2 vector<vecll>
#define vec3 vector<vec2d>
#define vecll3 vector<vecll2d>
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(vector<T> v){for(T e:v)cout<<e<<" ";cout<<endl;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}

const ll MOD=1e9+7;
const int N=500000;
 
template <ll Modulus> class modint {
  using u64 = ll;
 
public:
  u64 a;
 
  constexpr modint(const u64 x = 0) noexcept : a(((x % Modulus) + Modulus)%Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
 
#define mint modint<MOD>
mint inv[N],comb[N],prd[N],invprd[N];
void calc_inv(){
    inv[1]=1;
    rep2(i,2,N-1){
        inv[i]=inv[MOD%i]*(-MOD/i);
    }
    return;
}
void calc_product(){
    prd[0]=prd[1]=1;
    invprd[0]=invprd[1]=1;
    rep2(i,2,N-1){
        prd[i]=prd[i-1]*i;
        invprd[i]=inv[i]*invprd[i-1];
    }
    return ;
}
mint cmb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return {prd[a]*invprd[b]*invprd[a-b]};
}
mint modpow(mint x,ll n){
    if(n==0) return 1;
    mint res=modpow(x*x,n/2);
    if(n&1) res=res*x;
    return res;
}
void calc(){calc_inv();calc_product();}
 

main(){
    calc();
    int n=in();
    if(n==2){
        cin>>n>>n;
        cout<<-1<<endl;return 0;
    }vec a;
    a.pb(0);
    rep(i,n){
        a.pb(in());
    }
    set<int> s;
    if(n==3){
        vec id;
        rep2(i,1,3)id.pb(i);
        do{
            bool flag=1;
            rep(i,2){
                if(a[id[i]]==id[i+1])flag=false;
            }
            if(flag){
                print(id);
                return 0;
            }
        }while(next_permutation(all(id)));
        cout<<-1<<endl;
    }
    else{
        vec ans;
        int now=1;
        ans.pb(now);
        rep2(i,2,n)s.insert(i);
        rep(i,n-2){
            auto it=s.begin();
            if(a[now]!=*it){
                ans.pb(*it);
                now=*it;
                s.erase(it);
            }
            else{
                it++;
                ans.pb(*it);
                now=*it;
                s.erase(it);
            }
        }
        int t=*(s.begin());
        vec c;
        int pos=ans.size()-1;
        while(pos>=0 && a[ans[pos]]==t){
            c.pb(ans[pos]);
            pos--;
        }
        if(!c.size()){
            rep(i,ans.size())cout<<ans[i]<<" ";cout<<t;return 0;
        }
        if(c.size()==1 && a[t]==c[0]){
            int pre=ans[pos-1];
            rep(i,pos-1)cout<<ans[i]<<" ";
            if(c[0]<t)
            if(a[pre]!=c[0]){
                cout<<pre<<" "<<c[0]<<" "<<ans[pos]<<" "<<t<<endl;
            }
            else{
                cout<<pre<<" "<<t<<" "<<ans[pos]<<" "<<c[0]<<endl;
            }
            else{
                if(a[pre]!=t){
                    cout<<pre<<" "<<t<<" "<<ans[pos]<<" "<<c[0]<<endl;
                }
                else{
                    cout<<pre<<" "<<c[0]<<" "<<ans[pos]<<" "<<t<<endl;
                }
            }
            return 0;
        }
        // print(ans);
        rep(i,pos+1)cout<<ans[i]<<" ";
        // int s=ans[pos];
        // int p=min(t,s);
        // c.pb(p);
        // int q=max(t,s);
        // sort(all(c));
        // if(c[0]==a[s]) swap(c[0],c[1]);
        // int d;
        // rep(i,c.size())if(c[i]==p)d=i;
        // if(d<c.size()-1 && a[max(t,s)] == a[d+1]){
        //     if(d+2!=c.size())swap(c[d+1],c[d+2]);
        //     else{
        //         if(max(t,s) > c[d+1] || a[min(t,s)]==c[d+1]){
        //             swap(c[d],c[d+1]);
        //         }
        //         else{
        //             c[d]=max(t,s);
        //             p=max(t,s);
        //             q=min(t,s);
        //         }
        //     }
        // }
        // rep(i,c.size()){
        //     cout<<c[i]<<" ";
        //     if(c[i]==p)cout<<q<<" ";
        // }
        sort(all(c));
        cout<<t<<" ";
        if(c[0]==a[t])swap(c[0],c[1]);
        print(c);
    }
}


Measured memory_bytes: 19448