#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

struct RMinQ{
private:
    int N;
    vector<long long> node, lazy;
    vector<bool> lazyFlg;
    long long DEFAULT;
public:
    void init(int n, long long def=9223372036854775807LL){
        DEFAULT = def;
        node.clear();
        lazy.clear();
        lazyFlg.clear();
        N = 1;
        while(N < n) N = (N<<1);
        for(int i=0; i<2*N-1; i++){
            node.push_back(DEFAULT);
            lazy.push_back(0LL);
            lazyFlg.push_back(false);
        }
    }
    void eval(int k, int l, int r){
        if(lazyFlg[k]){
            node[k] = lazy[k];
            if(r-l > 1){
                lazy[(k<<1)+1] = lazy[k];
                lazyFlg[(k<<1)+1] = true;
                lazy[(k<<1)+2] = lazy[k];
                lazyFlg[(k<<1)+2] = true;
            }
            lazy[k] = 0LL;
            lazyFlg[k] = false;
        }
        else{
            node[k] += lazy[k];
            if(r-l > 1){
                lazy[(k<<1)+1] += lazy[k];
                lazy[(k<<1)+2] += lazy[k];
            }
            lazy[k] = 0LL;
        }
    }
    void update(int a, long long x){
        update(a, a+1, x);
    }
    void update(int a, int b, long long x, int k=0, int l=0, int r=-1){
        if(a >= b) return;
        if(r == -1) r = N;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b){
            lazy[k] = x;
            lazyFlg[k] = true;
            eval(k, l, r);
        }
        else{
            update(a, b, x, (k<<1)+1, l, (l+r)>>1);
            update(a, b, x, (k<<1)+2, (l+r)>>1, r);
            node[k] = std::min(node[(k<<1)+1], node[(k<<1)+2]);
        }
    }
    void add(int a, long long x){
        add(a, a+1, x);
    }
    void add(int a, int b, long long x, int k=0, int l=0, int r=-1){
        if(a >= b) return;
        if(r == -1) r = N;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b){
            lazy[k] += x;
            eval(k, l, r);
        }
        else{
            add(a, b, x, (k<<1)+1, l, (l+r)>>1);
            add(a, b, x, (k<<1)+2, (l+r)>>1, r);
            node[k] = std::min(node[(k<<1)+1], node[(k<<1)+2]);
        }
    }
    long long min(int a, int b, int k=0, int l=0, int r=-1){
        if(a >= b) return 9223372036854775807LL;
        if(r == -1) r = N;
        if(b <= l || r <= a) return 9223372036854775807LL;
        eval(k, l, r);
        if(a <= l && r <= b) return node[k];
        return std::min(min(a, b, (k<<1)+1, l, (l+r)>>1), min(a, b, (k<<1)+2, (l+r)>>1, r));
    }
    long long m;
    int find(int a, int b, int k=0, int l=0, int r=-1){
        if(r == -1){
            m = min(a, b);
            r = N;
        }
        if(r <= a || b <= l) return INT_MAX;
        if(r-l == 1){
            if(node[k] == m) return l;
            else return INT_MAX;
        }
        if(a <= l && r <= b){
            long long valueL = min(a, b, (k<<1)+1, l, (l+r)>>1);
            if(valueL == m) return find(a, b, (k<<1)+1, l, (l+r)>>1);
            long long valueR = min(a, b, (k<<1)+2, (l+r)>>1, r);
            if(valueR == m) return find(a, b, (k<<1)+2, (l+r)>>1, r);
            return INT_MAX;
        }
        return std::min(find(a, b, (k<<1)+1, l, (l+r)>>1), find(a, b, (k<<1)+2, (l+r)>>1, r));
    }
};

struct RMaxQ{
private:
    int N;
    vector<long long> node, lazy;
    vector<bool> lazyFlg;
    long long DEFAULT;
public:
    void init(int n, long long def=-9223372036854775807LL){
        DEFAULT = def;
        node.clear();
        lazy.clear();
        lazyFlg.clear();
        N = 1;
        while(N < n) N = (N<<1);
        for(int i=0; i<2*N-1; i++){
            node.push_back(DEFAULT);
            lazy.push_back(0LL);
            lazyFlg.push_back(false);
        }
    }
    void eval(int k, int l, int r){
        if(lazyFlg[k]){
            node[k] = lazy[k];
            if(r-l > 1){
                lazy[(k<<1)+1] = lazy[k];
                lazyFlg[(k<<1)+1] = true;
                lazy[(k<<1)+2] = lazy[k];
                lazyFlg[(k<<1)+2] = true;
            }
            lazy[k] = 0LL;
            lazyFlg[k] = false;
        }
        else{
            node[k] += lazy[k];
            if(r-l > 1){
                lazy[(k<<1)+1] += lazy[k];
                lazy[(k<<1)+2] += lazy[k];
            }
            lazy[k] = 0LL;
        }
    }
    void update(int a, long long x){
        update(a, a+1, x);
    }
    void update(int a, int b, long long x, int k=0, int l=0, int r=-1){
        if(a >= b) return;
        if(r == -1) r = N;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b){
            lazy[k] = x;
            lazyFlg[k] = true;
            eval(k, l, r);
        }
        else{
            update(a, b, x, (k<<1)+1, l, (l+r)>>1);
            update(a, b, x, (k<<1)+2, (l+r)>>1, r);
            node[k] = std::max(node[(k<<1)+1], node[(k<<1)+2]);
        }
    }
    void add(int a, long long x){
        add(a, a+1, x);
    }
    void add(int a, int b, long long x, int k=0, int l=0, int r=-1){
        if(a >= b) return;
        if(r == -1) r = N;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b){
            lazy[k] += x;
            eval(k, l, r);
        }
        else{
            add(a, b, x, (k<<1)+1, l, (l+r)>>1);
            add(a, b, x, (k<<1)+2, (l+r)>>1, r);
            node[k] = std::max(node[(k<<1)+1], node[(k<<1)+2]);
        }
    }
    long long max(int a, int b, int k=0, int l=0, int r=-1){
        if(a >= b) return -9223372036854775807LL;
        if(r == -1) r = N;
        if(b <= l || r <= a) return -9223372036854775807LL;
        eval(k, l, r);
        if(a <= l && r <= b) return node[k];
        return std::max(max(a, b, (k<<1)+1, l, (l+r)>>1), max(a, b, (k<<1)+2, (l+r)>>1, r));
    }
    long long m;
    int find(int a, int b, int k=0, int l=0, int r=-1){
        if(r == -1){
            m = max(a, b);
            r = N;
        }
        if(r <= a || b <= l) return INT_MAX;
        if(r-l == 1){
            if(node[k] == m) return l;
            else return INT_MAX;
        }
        if(a <= l && r <= b){
            long long valueL = max(a, b, (k<<1)+1, l, (l+r)>>1);
            long long valueR = max(a, b, (k<<1)+2, (l+r)>>1, r);
            if(valueL == m) return find(a, b, (k<<1)+1, l, (l+r)>>1);
            if(valueR == m) return find(a, b, (k<<1)+2, (l+r)>>1, r);
            return INT_MAX;
        }
        return std::min(find(a, b, (k<<1)+1, l, (l+r)>>1), find(a, b, (k<<1)+2, (l+r)>>1, r));
    }
};

int N;
int a[100000];

RMinQ rmq;
RMaxQ ema;
bool used[100000] ={};
vector<int> ans;

signed main(){
    cin >> N;
    if(N == 2){
        cout << -1 << endl;
        return 0;
    }
    rep(i, N){
        cin >> a[i];
        a[i]--;
    }
    
    rmq.init(N);
    rep(i, N) rmq.update(i, i);
    ema.init(N, 0);
    rep(i, N) ema.add(a[i], 1);
    int ng = -1;
    rep(i, N-3){
        int idx = rmq.min(0, N);
        if(ng == idx){
            idx = rmq.min(idx+1, N);
        }
        if(ema.max(0, N) == N-1-i){
            if(!used[ema.find(0, N)]) idx = ema.find(0, N);
        }
        ans.pb(idx);
        used[idx] = true;
        rmq.update(idx, INT_MAX);
        ema.add(a[idx], -1);
        ng = a[idx];
    }
    vector<int> tmp;
    rep(i, N){
        if(!used[i]) tmp.pb(i);
    }
    do{
        if(ng != tmp[0] && a[tmp[0]] != tmp[1] && a[tmp[1]] != tmp[2]){
            ans.pb(tmp[0]);
            ans.pb(tmp[1]);
            ans.pb(tmp[2]);
            break;
        }
    } while(next_permutation(all(tmp)));

    rep(i, N){
        if(i != 0) cout << " ";
        cout << ans[i]+1;
    }
    cout << endl;
}

Measured memory_bytes: 13496