#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(1e5)+10;
int n,a[maxn],cur;
int d[maxn],cnt[maxn];
int l[maxn],r[maxn];
bool vis[maxn];
void dfs(int x,int lst) {
	if (x>n) {
		for (int i=1;i<=n;i++)
			printf("%d ",d[i]);
		printf("\n");
		exit(0);
	}
	if (!vis[lst]&&cnt[lst]==n-x) return;
	int pos=cur;
	for (int i=1;i<=n-x+1;i++) {
		d[x]=pos;
		if (pos!=lst) {
			r[l[pos]]=r[pos];
			l[r[pos]]=l[pos];
			vis[pos]=1;
			if (pos==cur) cur=r[pos];
			cnt[a[pos]]--;
			dfs(x+1,a[pos]);
			cnt[a[pos]]++;
			if (r[pos]==cur) cur=pos;
			vis[pos]=0;
			r[l[pos]]=pos;
			l[r[pos]]=pos;
		}
		pos=r[pos];
	}
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(a[i]),cnt[a[i]]++;
	for (int i=2;i<=n;i++) l[i]=i-1;
	for (int i=1;i<n;i++) r[i]=i+1;
	cur=1; dfs(1,0);	
	printf("-1\n");
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/