#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	vector<int>v(N);
	priority_queue<pair<int, int>>PQ;
	vector<int>used(N);
	for (auto &i : v) {
		cin >> i;
		i--;
		used[i]++;
	}
	for (int i = 0; i < N; i++) {
		PQ.push({ used[i],i });
	}
	if (N == 2) {
		cout << -1 << endl;
		return 0;
	}
	if (N == 3) {
		vector<int>p(N);
		for (int i = 0; i < N; i++) {
			p[i] = i;
		}
		do {
			bool flag = true;
			for (int i = 0; i + 1 < N; i++) {
				if (v[p[i]] == p[i + 1])flag = false;
			}
			if (flag) {
				for (auto i : p)cout << i + 1 << " ";
				cout << endl;
				return 0;
			}
		} while (next_permutation(p.begin(), p.end()));
		cout << -1 << endl;
		return 0;
	}
	vector<int>ans;
	set<int>s;
	for (int i = 0; i < N; i++)s.insert(i);
	int nx = -1;
	vector<int>er(N);
	while (s.size() > 4) {
		while (er[PQ.top().second])PQ.pop();
		while (PQ.top().first != used[PQ.top().second]) {
			PQ.push({ used[PQ.top().second],PQ.top().second });
			PQ.pop();
		}
		if (PQ.top().first + 1 == s.size()) {
			ans.push_back(PQ.top().second);
			nx = v[PQ.top().second];
			used[nx]--;
			s.erase(PQ.top().second);
			PQ.pop();
			continue;
		}
		auto it = s.begin();
		if (nx == *it)it++;
		ans.push_back(*it);
		nx = v[*it];
		used[nx]--;
		er[*it] = 1;
		s.erase(it);
	}
	//for (auto i : ans)cout << i + 1 << endl;
	vector<int>p;
	for (auto i : s) {
		p.push_back(i);
	}
	do {
		bool flag = true;
		int cnx = nx;
		for (int i = 0; i < 4; i++) {
			if (cnx == p[i])flag = false;
			cnx = v[p[i]];
		}
		if (flag) {
			for (auto i : p)ans.push_back(i);
			for (auto i : ans)cout << i + 1 << " ";
			cout << endl;
			return 0;
		}
	} while (next_permutation(p.begin(), p.end()));
	cout << -1 << endl;
	return 0;
}