#if 1

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <random>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
int32_t num[112345];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (int32_t i = 1; i <= N; i++)
	{
		in >> num[i];
	}
	if (N == 2) {
		out << "-1" << endl;
		return 0;
	}
	std::vector<int> result;
#ifdef _MSC_VER
	//N = 1000;
	//std::mt19937_64 engine;
	//std::uniform_int_distribution<> dist(1, N);
	for (size_t CCCCC = 0; CCCCC < 1; CCCCC++)
	{
		//for (int32_t i = 1; i <= N; i++)
		//{
		//	num[i] = i;
		//	while (num[i] == i) {
		//		num[i] = dist(engine);
		//	}
		//}
		//result.clear();
#endif
		std::set<int32_t> rem;
		for (int32_t i = 1; i <= N; i++)
		{
			rem.insert(i);
		}
		int error = -1;
		for (int32_t COUNT = 1; COUNT <= N - 1; COUNT++)
		{
			auto iter = rem.begin();
			auto v1 = *iter;
			++iter;
			auto v2 = *iter;
			if (v1 != error) {
				result.push_back(v1);
				error = num[v1];
				iter = rem.begin();
			}
			else {
				result.push_back(v2);
				error = num[v2];
			}
			rem.erase(iter);
		}
		{
			auto v1 = *rem.begin();
			assert(rem.size() == 1);
			rem.clear();
			if (error == v1) {
				{
					auto prev = result.back(); result.pop_back();
					rem.insert(prev);
					if (result.empty()) {
						error = -1;
					}
					else {
						error = num[result.back()];
					}
					if(num[v1] == prev) {
						auto preprev = result.back(); result.pop_back();
						rem.insert(preprev);
						if (result.empty()) {
							error = -1;
						}
						else {
							error = num[result.back()];
						}
						if (num[preprev] != v1) {
							if (error != prev) {
								result.push_back(prev);
								error = num[prev];
								rem.erase(prev);
								assert(error != preprev);
								result.push_back(preprev);
								error = num[preprev];
								rem.erase(preprev);
								assert(error != v1);
							}
						}
					}
				}
			}
			while (error == v1) {
				auto prev = result.back(); result.pop_back();
				rem.insert(prev);
				if (result.empty()) {
					error = -1;
				}
				else {
					error = num[result.back()];
				}
			}
			result.push_back(v1);
			error = num[v1];
		}
		static int COUNTCOUNT = 0;
		while (rem.size() > 1) {
			assert(result.size() < N);
			auto iter = rem.begin();
			auto v1 = *iter;
			auto v2 = *(++iter);
			if (v1 != error) {
				result.push_back(v1);
				error = num[v1];
				iter = rem.begin();
			}
			else {
				assert(COUNTCOUNT == 0);
				++COUNTCOUNT;
				result.push_back(v2);
				error = num[v2];
			}
			rem.erase(iter);
		}
		if (rem.size() == 1) {
			auto v1 = *rem.begin();
			rem.clear();
			assert(error != v1);
			result.push_back(v1);
			error = num[v1];
		}
		assert(result.size() == N);

		for (size_t i = 0; i < result.size() - 1; i++)
		{
			assert(result[i + 1] != num[result[i]]);
		}

#ifdef _MSC_VER
	}
#endif

	for (size_t i = 0; i < result.size() - 1; i++)
	{
		out << result[i] << ' ';
	}
	out << result.back() << endl;

	return 0;
}
#endif


Measured memory_bytes: 6400