#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
using namespace std;

/* debug macros */
#ifdef WAFDAYO
#define DBG_PRINT(s, t, u) { std::cerr << s << " \e[2m=\e[m \e[1m" << t << "\e[m" << u; }
#else
#define DBG_PRINT(s, t, u) {}
#endif
#define dbg(x) DBG_PRINT(#x, x, std::endl)
#define dbgc(x) DBG_PRINT(#x, x, ", ")
#define idbg(x, i) DBG_PRINT(#x "[" << i << "]", x[i], std::endl)
#define idbgc(x, i) DBG_PRINT(#x "[" << i << "]", x[i], ", ")

/* IO utilities */
struct read_item { read_item() {}; template<class T> operator T() { T t; std::cin >> t; return t; } };

/* types and constants */
typedef long long i64;
const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

void decrease(vector<int>& count, int i, set<pair<int,int>>& count_nums) {
	count[i] -= 1;
	if(count_nums.erase({count[i] + 1, i}) == 1) {
		count_nums.insert({count[i], i});
	}
}

void remove_from_pq(priority_queue<int>& pq, int x) {
	priority_queue<int> tmp;
	while(!pq.empty()) {
		int v = pq.top();
		pq.pop();
		if(v != x) {
			tmp.push(v);
		}
	}
	swap(tmp, pq);
}

int main() {

	const int n = read_item();
	vector<int> xs(n + 1);
	vector<int> count(n + 1);

	for(int i = 0; i < n; i++) {
		int x = read_item();
		x -= 1;
		xs[i] = x;
		count[x] += 1;
		count[i] += 1;
	}
	xs[n] = n;
	count[n] += 2;

	set<pair<int,int>> count_nums;
	for(int i = 0; i < n + 1; i++) {
		count_nums.insert({count[i], i});
	}

	int last = n;
	priority_queue<int> rem;
	for(int i = 0; i < n + 1; i++) {
		rem.push(-i);
	}

	vector<int> ans;

	while(rem.size() > 5) {

		dbg(last);

		int x = (last < n ? xs[last] : n);

		decrease(count, x, count_nums);
		decrease(count, last, count_nums);
		if(last != n) {
			count_nums.erase({count[last], last});
		}

		auto most = count_nums.rbegin();
		dbgc(most->first); dbg(most->second);
		if(most->first >= rem.size() - 1) {
			int v = most->second;
			ans.push_back(v);
			last = v;
			remove_from_pq(rem, -v);
			continue;
		}

		array<int,3> vs;
		for(int i = 0; i < 3; i++) {
			vs[i] = -rem.top();
			rem.pop();
		}

		int used = 0;
		while(used < 3 && (vs[used] == x || vs[used] == last)) {
			used += 1;
		}
		assert(used < 3);

		for(int i = 0; i < 3; i++) {
			if(i != used) {
				rem.push(-vs[i]);
			}
		}

		int v = vs[used];
		ans.push_back(v);
		last = v;
	}

	vector<int> right(rem.size());
	const int rlen = right.size();

	for(int i = 0; i < rlen; i++) {
		right[i] = -rem.top();
		rem.pop();
	}

	sort(right.begin(), right.end());

	while(true) {

		if(right[rlen - 1] != n) {
			if(!next_permutation(right.begin(), right.end())) {
				break;
			}
			continue;
		}

		bool ok = true;
		for(int i = 0; i < rlen; i++) {
			int p = (i == 0) ? last : right[i - 1];
			if(p < n && xs[p] == right[i]) {
				ok = false;
			}
		}

		if(ok) {
			for(int i = 0; i < rlen; i++) {
				ans.push_back(right[i]);
			}
			break;
		}

		if(!next_permutation(right.begin(), right.end())) {
			break;
		}
	}

	if(ans.size() < n) {
		printf("-1\n");
		return 0;
	}

	for(int i = 0; i < n; i++) {
		printf("%d%c", ans[i] + 1, i == n - 1 ? '\n' : ' ');
	}

	return 0;
}

/* wafdayo~~~ */


Measured memory_bytes: 7024