#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rs64() {
	int64_t n;
	scanf("%" SCNd64, &n);
	return n;
}


int main() {
	int n = ri();
	int a[n];
	for (auto &i : a) i = ri() - 1;
	std::set<int> left;
	for (int i = 0; i < n; i++) left.insert(i);
	
	std::map<int, int> taboo;
	for (int i = 0; i < n; i++) taboo[a[i]]++;
	
	auto zen = [&] (int no) {
		std::vector<int> res(left.begin(), left.end());
		int n = left.size();
		bool ok = false;
		do {
			if (res[0] == no) continue;
			bool cont = true;
			for (int i = 0; i + 1 < n; i++) if (res[i + 1] == a[res[i]]) {
				cont = false;
			}
			if (!cont) continue;
			ok = true;
			break;
		} while (std::next_permutation(res.begin(), res.end()));
		if (!ok) system("sleep 0.3"), assert(n != 6);
		if (!ok) return std::vector<int>();
		return res;
	};
	
	std::vector<int> res;
	int last_taboo = -1;
	bool ok = true;
	int i = 0;
	for (; i < n - 4; i++) {
		auto next = left.begin();
		std::set<int> no{last_taboo};
		if (taboo.size() == 3) {
			std::vector<std::pair<int, int> > all;
			for (auto j : taboo) all.push_back({j.second, j.first});
			std::sort(all.begin(), all.end());
			if (all[0].first == 1 && all[1].first == 1 && all[2].first == (int) left.size() - 2) {
				if (a[all[0].second] == all[2].second && a[all[2].second] == all[0].second) no.insert(all[0].second);
				if (a[all[1].second] == all[2].second && a[all[2].second] == all[1].second) no.insert(all[1].second);
			}
		}
		while (no.count(*next)) next++;
		if (taboo.size() == 2) {
			std::vector<std::pair<int, int> > all;
			for (auto j : taboo) all.push_back({j.second, j.first});
			std::sort(all.begin(), all.end());
			if (all[0].first == 1 && all[1].first == (int) left.size() - 1) {
				next = left.find(all[1].second);
				assert(*next != last_taboo);
			}
		} else if (taboo.size() == 1 && taboo.begin()->second == (int) left.size() - 1) {
			next = left.find(taboo.begin()->first);
		}
		res.push_back(*next);
		/*
		std::cerr << *next << " " << taboo.size() << std::endl;
		std::cerr << "no:";
		for (auto j : no) std::cerr << j << " ";
		std::cerr << std::endl;*/
		
		if (taboo.count(a[*next]) && !--taboo[a[*next]]) taboo.erase(a[*next]);
		taboo.erase(*next);
		
		last_taboo = a[*next];
		left.erase(*next);
	}
	auto tmp = zen(last_taboo);
	res.insert(res.end(), tmp.begin(), tmp.end());
	if (!ok || !tmp.size()) {
		std::cout << -1 << std::endl;
	} else {
		for (auto i : res) std::cout << i + 1 << " ";
		std::cout << std::endl;
	}
	
	return 0;
}
