#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007 ;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
	int i,n;cin>>n;
	if(n==2){cout<<"-1\n";return 0;}
	vector<int>a(n+1);
	vector<int>g(n+1);
	for(i=1;i<=n;i++){cin>>a[i];g[a[i]]++;}a[0]=0;
	//残り全員がダメ を持ってると優先
	int mae=0;
	deque<int>aaa(n);
	priority_queue<pair<int,int>>que;
	for(i=1;i<=n;i++){aaa[i-1]=i;que.push(mp(g[i],i));}
	vector<bool>use(n+1);
	for(i=1;i<=n-6;i++){
		int t;bool yu=false;
		while(que.size()&&que.top().fir>=n-i){
			t=que.top().sec;
			que.pop();
			if(use[t]){continue;}
			else if(g[t]>=n-i){yu=true;break;}
			else{que.push(mp(g[t],t));}
		}//必ずそいつを入れる
		if(yu){aaa.erase(lower_bound(aaa.begin(),aaa.end(),t));}
		else if(a[mae]==aaa[0]){t=aaa[1];aaa.erase(aaa.begin()+1);}
		else{t=aaa[0];aaa.erase(aaa.begin());}
		
		//for(auto it:aaa){cerr<<it;}cerr<<endl;
		cout<<t<<" ";
		use[t]=1;
		g[a[t]]--;
		mae=t;
	}
	//残りはわずかなのでnext_permutationします
	do{
		int m=aaa.size();
		if(a[mae]==aaa[0]){continue;}
		bool dame=false;
		for(i=0;i<m-1;i++){
			if(a[aaa[i]]==aaa[i+1]){dame=true;break;}
		}
		if(dame){continue;}
		for(i=0;i<m;i++){cout<<aaa[i]<<" ";}
		return 0;
	}while(next_permutation(aaa.begin(),aaa.end()));
	cout<<"-1\n";
	return 0;
}
