#include <bits/stdc++.h>
using namespace std;

#define rep(i, s, t) for (int i = s; i < int(t); ++i)

#define sc	scanf
#define pr	printf
#define ff	first
#define ss	second
#define mp	make_pair
#define pb	push_back
#define eb	emplace_back
#define range(c)	c.begin(), c.end()
#define const_range(c)	c.cbegin(), c.cend()
#define lowbit(x)	((x) & -(x))
#define pop_count	__builin_popcount
#define pop_count64	__builtin_popcountll
#define tail_count	__builtin_ctz
#define tail_count64	__builtin_ctzll
#define lead_count	__builtin_clz
#define lead_count64	__builtin_clzll

#define temp_name template<typename

temp_name T1, typename T2> ostream& operator<< (ostream& os, const pair<T1, T2>& p) { return os << "<" << p.ff << "," << p.ss << ">"; }
#define container_ostream(container)						\
temp_name... T> ostream& operator<< (ostream& os, const container<T...>& c) {	\
	if (c.empty()) return os << "{ }";					\
	auto iter = c.cbegin();							\
	os << "{ " << *iter;							\
	while (++iter != c.cend()) os << ", " << *iter;				\
	return os << " }";							\
}
container_ostream(vector);
container_ostream(set);
container_ostream(map);

void dbg() { cerr << endl;}
temp_name Head, typename... Tail> void dbg(Head h, Tail... t) { cerr << " " << h; dbg(t...); }

#ifdef LOCAL
#define debug(...) cerr << "[ "#__VA_ARGS__" ] :", dbg(__VA_ARGS__)
#else
#define debug(...) 0
#endif

typedef long long i64;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<i64> vl;

temp_name T> T& minn(T& x, const T& y) { return x = min(x, y); }
temp_name T> T& maxx(T& x, const T& y) { return x = max(x, y); }

constexpr const int mod = 1000000007;
constexpr int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; }
constexpr int sub(int a, int b) { return a < b ? mod + a - b : a - b; }
constexpr int mul(int a, int b) { return 1LL * a * b % mod; }
#define more_para(type, func) temp_name... T> constexpr type func(type a, type b, T... c) { return func(func(a, b), c...); }
more_para(int, add);
more_para(int, sub);
more_para(int, mul);
constexpr int square(int a) { return mul(a, a); }
constexpr int fpow(int a, int b) { return b ? mul(b & 1 ? a : 1, square(fpow(a, b >> 1))) : 1; }

constexpr const int maxn = 1 << 17;
int a[maxn], cnt[maxn], ans[maxn], vis[maxn];
set<int> have[maxn], wait;

void game_over() { cout << "-1" << endl; exit(0); }

int choice(int x) {
	wait.erase(x);
	have[cnt[x]].erase(x);
	vis[x] = 1;
	int y = a[x];
	if (vis[y]) return x;
	have[cnt[y]].erase(y);
	--cnt[y];
	have[cnt[y]].insert(y);
	return x;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	rep(i, 1, n + 1) cin >> a[i], ++cnt[a[i]];
	if (n == 2) return cout << "-1" << endl, 0;
	rep(i, 1, n + 1) have[cnt[i]].insert(i);
	rep(i, 1, n + 1) wait.insert(i);
	rep(i, 1, n - 2) {
		if (have[n - i].empty()) {
			if (a[ans[i - 1]] == *wait.cbegin()) {
				ans[i] = choice(*next(wait.cbegin()));
			} else {
				ans[i] = choice(*wait.cbegin());
			}
		} else {
			ans[i] = choice(*have[n - i].cbegin());
		}
	}
	vi p(const_range(wait));
	do {
		rep(i, 0, p.size()) ans[n - p.size() + i + 1] = p[i];
		bool ok = true;
		rep(i, n - p.size(), n) if (a[ans[i]] == ans[i + 1]) ok = false;
		if (ok) break;
	} while (next_permutation(range(p)));
	rep(i, 1, n + 1) cout << ans[i] << " \n"[i == n];
}


Measured memory_bytes: 18432