#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <queue>
#define lson (x << 1)
#define rson ((x << 1) | 1)
#define mid ((l + r) >> 1)
using namespace std;
typedef long long LL;

LL n,m,k;
LL a[500005],b[500005];
LL vis[500005] = {0};
LL cnt[500005] = {0};

LL cnn[800005],cid[800005],tot[800005],mii[800005];

void pushup(LL x){
	cnn[x] = max(cnn[lson],cnn[rson]);
	if(cnn[lson] > cnn[rson]) cid[x] = cid[lson];
	else cid[x] = cid[rson];
	
	tot[x] = tot[lson] + tot[rson];
	if(tot[lson]) mii[x] = mii[lson];
	else mii[x] = mii[rson];
}

void build(LL x,LL l,LL r){
	if(l == r){
		cnn[x] = cnt[l];
		cid[x] = l;
		tot[x] = 1;
		mii[x] = l;
		return;
	}
	build(lson,l,mid);
	build(rson,mid + 1,r);
	pushup(x);
}

LL getmin(LL x,LL l,LL r,LL L,LL R){
	if(L > R) return n + 1;
	if(L <= l && r <= R) return mii[x];
	LL ret = n + 1;
	if(L <= mid) ret = min(ret,getmin(lson,l,mid,L,R));
	if(R > mid) ret = min(ret,getmin(rson,mid + 1,r,L,R));
	return ret;
}

LL getmax(){
	return cid[1];
}

void modify(LL x,LL l,LL r,LL L,LL R,LL v){
	if(L <= l && r <= R){
		cnn[x] --;
		return;
	}
	if(L <= mid) modify(lson,l,mid,L,R,v);
	if(R > mid) modify(rson,mid + 1,r,L,R,v);
	pushup(x);
}

void modify2(LL x,LL l,LL r,LL L,LL R,LL v){
	if(L <= l && r <= R){
		tot[x] --;
		mii[x] = n + 1;
		cnn[x] = -1;
		cid[x] = n + 1;
		return;
	}
	if(L <= mid) modify2(lson,l,mid,L,R,v);
	if(R > mid) modify2(rson,mid + 1,r,L,R,v);
	pushup(x);
}

LL judge(){
	memset(cnt,0,sizeof(cnt));
	for(LL i = 1;i <= n;i ++) cnt[b[i]] ++;
	for(LL i = 1;i <= n;i ++){
		if(cnt[i] != 1) return 0;
		if(b[i + 1] == a[b[i]]) return 0;
	}
}

LL u[3],dfv[3] = {0};

void dfs2(LL x){
	if(x > n){
		if(judge()){
			for(LL i = 1;i <= n;i ++) cout << b[i] << (i == n ? '\n' : ' ');
			exit(0);
		}
		else return;
	}
	for(LL i = 0;i < 3;i ++){
		if(dfv[i]) continue;
		dfv[i] = 1;
		b[x] = u[i];
		dfs2(x + 1);
		dfv[i] = 0;
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for(LL i = 1;i <= n;i ++) cin >> a[i];
	for(LL i = 1;i <= n;i ++) cnt[a[i]] ++;
	build(1,1,n);
	
	if(n <= 2){
		cout << -1 << endl;
		return 0;
	}
	
	LL nxt = -1,id;
	for(LL i = 1;i <= n - 3;i ++){
//		cout << getmax() << ' ' << cnt[getmax()] << ' ' << n - i << endl;
		if(cnt[getmax()] == n - i){
			id = getmax();
			nxt = a[id]; b[i] = id; cnt[a[b[i]]] --;
			modify(1,1,n,a[b[i]],a[b[i]],-1);
			modify2(1,1,n,id,id,-1);
		}
		else{
			id = getmin(1,1,n,1,n);
			if(id == nxt) id = getmin(1,1,n,id + 1,n);
			nxt = a[id];
			b[i] = id; cnt[a[b[i]]] --;
			modify(1,1,n,a[b[i]],a[b[i]],-1);
			modify2(1,1,n,id,id,-1);
		}
	}
	
	u[0] = u[1] = u[2] = -1;
	for(LL i = 1;i <= n - 3;i ++) vis[b[i]] = 1;
	for(LL i = 1;i <= n;i ++){
		if(!vis[i]){
			if(u[0] == -1) u[0] = i;
			else if(u[1] == -1) u[1] = i;
			else u[2] = i;
		}
	}
	
	dfs2(n - 2);
	
	return 0;
}