#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;
 
vector<ll> G[550010];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
// priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
//ll mod = 998244353;
ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,h,r,l,q;
ll k;
ll x[500005], y[500005], z[500005], w[500005];
char s[500005];
ll hated[500005];
ll hating[500005];
bool used[500005];

vector<ll> ans;
vector<ll> waiting;

ll cnt;

bool last(ll now_hated){
    vector<ll> table;
    for(ll i=0;i<waiting.size();i++){
        ll v = waiting[i];
        if(used[v])continue;
        table.pb(v);
    }
    sort(table.begin(), table.end());
    do{
        bool dame = false;
        for(ll i=0;i<table.size();i++){
            if(i == 0){
                if(table[i] == now_hated)dame = true;
            }else{
                if(table[i] == hating[table[i-1]])dame = true;
            }
        }
        if(!dame){
            for(ll i=0;i<table.size();i++){
                ans.pb(table[i]);
            }
            return true;
        }

    }while(next_permutation(table.begin(), table.end()));
    return false;
}

void put(ll num){
    used[num] = true;
    ans.pb(num);
    hated[hating[num]]--;
    return;
}

ll find(ll num){
    vector<ll> tmp;
    ll res = -1;
    ll cnt = 0;
    while(true){
        ll v = waiting.back();
        waiting.pop_back();
        if(used[v]){
            // 使われているのでノーカウント
        }else{
            // 使われていないのでカウント
            res = v;
            tmp.pb(v);
            cnt ++;
            if(cnt == num)break;
        }
    }
    res = tmp[num - 1];
    for(ll i=0;i<tmp.size();i++){
        waiting.pb(tmp[tmp.size() - 1 -i]);
    }
    return res;
}

ll hated_master(ll cnt){
    ll v1 = find(1);
    ll v2 = find(2);
    if(hated[hating[v1]] >= cnt - 1 && !used[hating[v1]]){
        return hating[v1];
    }else if(hated[hating[v2]] >= cnt - 1 && !used[hating[v2]]){
        return hating[v2];
    }else{
        return -1;
    }
}

int main(){
    cin >> n;
    for(ll i=0;i<n;i++){
        cin >> hating[i+1];
    }        
    for(ll i=1;i<=n;i++){
        hated[hating[i]] ++;
    }
    for(ll i=n;i>=1;i--){
        waiting.pb(i);
    }
    ll now_hated = -1;
    cnt = n;
    while(true){
        
        if(cnt <= 5){
            bool res = last(now_hated);
            if(!res){
                p(-1);
                return 0;
            }
            break;
        }else{
            ll v = hated_master(cnt);
            if(hated[v] >= cnt){
                p(-1);
                return 0;
            }
            if(v == -1){
                v = find(1);
                if(v == now_hated){
                    v = find(2);
                }
            }
            put(v);
            now_hated = hating[v];
        }
        cnt--;
        for(ll i=0;i<ans.size();i++){
            //pe(ans[i]);
        }
        //el;
    }
    assert(ans.size() == n);
    for(ll i=0;i<ans.size();i++){
        pe(ans[i]);
    }
    el;
    return 0;



}
 











Measured memory_bytes: 31988