#include <bits/stdc++.h>
using namespace std;
inline int read(){
    int x = 0; char c = getchar();
    while (!isdigit(c)) c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0',c = getchar();
    return x;
}
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }
const int N = 100050;
int n,a[N];

namespace subtask0{
	int ans[100],vis[100]; bool ok;
	int p[100];
	inline void chk(){
		for (int i = 2; i <= n; ++i) if (a[ans[i-1]] == ans[i]) return;
		ok = 1; for (int i = 1; i <= n; ++i) p[i] = ans[i];
		return; 
	}
	inline void dfs(int dep){
		if (ok) return;
		if (dep > n){ chk(); return; }
		for (int i = 1; i <= n; ++i) if (!vis[i]){
			vis[i] = 1,ans[dep] = i;
			dfs(dep+1);
			vis[i] = 0;
		}
	}
	inline void solve(){
		ok = 0; memset(vis,0,sizeof(vis)); memset(ans,0,sizeof(ans)); dfs(1);
		if (!ok){ puts("-1"); return; }
		for (int i = 1; i <= n; ++i) cout << p[i] << ((i<n) ? (' '):('\n'));
	}
}

int mx[N<<2],mxi[N<<2],data[N<<2],cnt[N];
inline void Build(int o,int l,int r){
	if (l^r){
		int mid = l+r>>1; Build(o<<1,l,mid); Build(o<<1|1,mid+1,r);
		mx[o] = max(mx[o<<1],mx[o<<1|1]); data[o] = min(data[o<<1],data[o<<1|1]);
		mxi[o] = mxi[ (mx[o<<1]>mx[o<<1|1]) ? (o<<1) : (o<<1|1) ];
		return;
	}
	mx[o] = cnt[l]; data[o] = (mx[o] >= 0) ? (l) : (n+1); mxi[o] = l;
}
inline int Ask(int o,int l,int r,int p){
	if (l==r) return mx[o];
	int mid = l+r>>1; return (p<=mid) ? Ask(o<<1,l,mid,p) : Ask(o<<1|1,mid+1,r,p);
} 
inline void Add(int o,int l,int r,int p,int v){
	if (l==r){ mx[o]=v; data[o] = (mx[o] >= 0) ? (l) : (n+1); return; }
	int mid = l+r>>1; if (p<=mid) Add(o<<1,l,mid,p,v); else Add(o<<1|1,mid+1,r,p,v);
	mx[o] = max(mx[o<<1],mx[o<<1|1]); data[o] = min(data[o<<1],data[o<<1|1]);
	mxi[o] = mxi[ (mx[o<<1]>mx[o<<1|1]) ? (o<<1) : (o<<1|1) ];
}
inline int Nowv(){ return data[1]; }
inline int Query(int pos){ if (pos==0) return -1; return Ask(1,1,n,pos); }
inline void Modify(int x,int v){ cnt[x] = v; Add(1,1,n,x,v); }


int ans[N];
int vis[N],nowc[N],lc;
int qwq;
inline void chk(){
	for (int i = qwq; i <= n; ++i) if (ans[i]==a[ans[i-1]]) return;
	for (int i = 1; i <= n; ++i) write(ans[i]),putchar((i<n)?(' '):('\n'));
	exit(0);
}
inline void dfs(int dep){
	if (dep>n){ chk(); return; }
	for (int i = 1; i <= lc; ++i) if (!vis[i]){
		vis[i] = 1;
		ans[dep] = nowc[i];
		dfs(dep+1);
		vis[i] = 0;
	}
}
inline void solve_force(int l,int r){
	qwq = l;
	for (int i = 1; i <= n; ++i) if (Query(i) >= 0) nowc[++lc] = i,vis[lc] = 0;
	dfs(l);
}
inline bool unproperty(){
	for (int i = 1; i <= n; ++i) cnt[i] = 0;
	for (int i = 1; i <= n; ++i) ++cnt[ans[i]];
	for (int i = 1; i <= n; ++i) if (cnt[i] != 1) return 1;
	for (int i = 2; i <= n; ++i) if (ans[i] == a[ans[i-1]]) return 1;
	return 0;
}
int main(){
	int i,banp,ret,siz,p;
	int pp,val;
	read(n);
	for (i = 1; i <= n; ++i) read(a[i]);
	for (i = 1; i <= n; ++i) if (a[i]==i) a[i]=0;
	for (i = 1; i <= n; ++i) ++cnt[a[i]];
//	if (n==2){ puts("-1"); return 0; }
	if (n<=8){ subtask0::solve(); return 0; }
	
	Build(1,1,n);
	for (banp = 0,siz = n,i = 1; i <= n; ++i,--siz){
		if (siz <= 6){
			solve_force(i,n); 
		}
		banp = a[ans[i-1]];
		if (banp != 0 && (ret=Query(banp)) >= 0){
			Modify(banp,-1);
			if (mx[1] == siz-1){
				p = mxi[1];
				ans[i] = p;
				Modify(ans[i],-1);
			}
			else{
				p = data[1];
				ans[i] = p;
				Modify(ans[i],-1);
			}
			pp = a[ans[i]];
			if ((val=Query(pp))>=0){ --val; Modify(pp,val); }
			Modify(banp,ret);
		}
		else{
			if (mx[1] == siz-1){
				p = mxi[1];
				ans[i] = p;
				Modify(ans[i],-1);
			}
			else{
				p = data[1];
				ans[i] = p;
				Modify(ans[i],-1);
			}
			pp = a[ans[i]];
			if ((val=Query(pp))>=0){ --val; Modify(pp,val); }
		}
	}
	if (unproperty()){ puts("-1"); return 0; }
	for (i = 1; i <= n; ++i) write(ans[i]),putchar((i<n)?(' '):('\n'));
}

Measured memory_bytes: 6528