#include <stdexcept>
#include <cstdint>
#include <type_traits>
#include <iterator>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cassert>
#include <initializer_list>
#include <string>
#include <set>
#include <utility>
namespace loquat {
namespace bitmanip {
template <typename T>
inline auto clz(T x) noexcept ->
	typename std::enable_if<sizeof(int) < sizeof(T), unsigned int>::type
{
	return __builtin_clzll(x);
}
template <typename T>
inline T clp2(T x) noexcept {
	if(x == 0u){ return 0u; }
	return T(1u) << (sizeof(T) * 8u - clz(x - 1));
}
}
}
namespace loquat {
template <typename Impl>
class range_query_behavior_wrapper {
public:
	using value_type = typename Impl::value_type;
private:
	Impl m_impl;
public:
	range_query_behavior_wrapper(Impl impl) : m_impl(std::move(impl)) { }
	value_type identity() const {
		return m_impl.identity();
	}
	value_type merge(const value_type& a, const value_type& b) const {
		return m_impl.merge(a, b);
	}
};
}
namespace loquat {
template <typename Behavior>
class segment_tree {
public:
	using behavior_type = Behavior;
	using value_type = typename behavior_type::value_type;
private:
	size_t m_actual_size;
	std::vector<value_type> m_values;
	range_query_behavior_wrapper<behavior_type> m_behavior;
	void initialize(){
		const auto m = m_values.size() / 2;
		for(size_t i = 0; i < m; ++i){
			const auto k = m - 1 - i;
			m_values[k] = m_behavior.merge(
				m_values[k * 2 + 1], m_values[k * 2 + 2]);
		}
	}
public:
	template <typename Iterator>
	segment_tree(
		Iterator first,
		Iterator last,
		const behavior_type& behavior = behavior_type())
		: m_actual_size(std::distance(first, last))
		, m_values(bitmanip::clp2(m_actual_size) * 2 - 1)
		, m_behavior(behavior)
	{
		const auto it = m_values.begin() + m_values.size() / 2;
		std::copy(first, last, it);
		initialize();
	}
	void update(size_t i, const value_type& x){
		i += m_values.size() / 2;
		m_values[i] = x;
		while(i > 0){
			i = (i - 1) / 2;
			m_values[i] = m_behavior.merge(
				m_values[i * 2 + 1], m_values[i * 2 + 2]);
		}
	}
	value_type query(size_t left, size_t right) const {
		const auto m = m_values.size() / 2;
		left += m; right += m;
		value_type l_value = m_behavior.identity(), r_value = l_value;
		while(left < right){
			if((left & 1u) == 0u){
				const auto& x = m_values[left];
				l_value = m_behavior.merge(l_value, x);
			}
			if((right & 1u) == 0u){
				const auto& x = m_values[right - 1];
				r_value = m_behavior.merge(x, r_value);
			}
			left  = left / 2;
			right = (right - 1) / 2;
		}
		return m_behavior.merge(l_value, r_value);
	}
};
}
using namespace std;
using pii = pair<int, int>;
static constexpr int INF = 1000000000;
struct range_query_behavior {
	using value_type = pii;
	value_type identity() const { return make_pair(-INF, 0); }
	value_type merge(const value_type& a, const value_type& b) const {
		return std::max(a, b);
	}
};
int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	vector<pii> init(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		--a[i];
		++init[a[i]].first;
		init[i].second = i;
	}
	loquat::segment_tree<range_query_behavior> st(init.begin(), init.end());
	set<int> pq;
	for(int i = 0; i < n; ++i){ pq.insert(i); }
	vector<int> b;
	while(pq.size() > 5){
		int x = -1;
		const auto p = st.query(0, n);
		if(p.first == pq.size() - 1){
			x = p.second;
		}else if(!b.empty() && a[b.back()] == *(pq.begin())){
			x = *(std::next(pq.begin()));
		}else{
			x = *(pq.begin());
		}
		pq.erase(x);
		b.push_back(x);
		const auto q = st.query(a[x], a[x] + 1);
		if(q.first > 0){ st.update(a[x], pii(q.first - 1, a[x])); }
		st.update(x, pii(-INF, 0));
	}
	const int m = min<int>(pq.size(), n);
	while(!pq.empty()){
		b.push_back(*(pq.begin()));
		pq.erase(b.back());
	}
	bool possible = false;
	do {
		bool accept = true;
		for(int i = 0; i < m; ++i){
			const int j = n - m + i;
			if(j == 0){ continue; }
			if(a[b[j - 1]] == b[j]){ accept = false; }
		}
		if(accept){
			possible = true;
			break;
		}
	} while(next_permutation(b.end() - m, b.end()));
	if(!possible){
		cout << -1 << endl;
	}else{
		for(const auto x : b){
			cout << (x + 1) << " ";
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 8704