#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n + 10, 0);
  vector<long long> cnt(n + 10, 0);
  for (long long i = (0); i < ((n)); ++i) cin >> a[i + 1], cnt[a[i]]++;
  if (n == 2 && a[1] == 2 && a[2] == 1) {
    cout << -1 << endl;
    return 0;
  }
  set<long long> st;
  for (long long i = (0); i < ((n)); ++i) st.insert(i + 1);
  vector<long long> ans, used(n + 1, 0);
  long long now = 1, cur = 0;
  while (ans.size() < n) {
    while (used[now]) now++;
    if (now == a[cur]) {
      auto itr = st.begin();
      itr++;
      long long nx = *itr;
      long long x = a[nx];
      if (used[x]) {
        ans.push_back(nx);
        used[nx]++;
        cnt[x]--;
        cur = nx;
        st.erase(st.find(nx));
      } else if (cnt[x] != n - 1 - ans.size()) {
        ans.push_back(nx);
        used[nx]++;
        cnt[x]--;
        cur = nx;
        st.erase(st.find(nx));
      } else {
        ans.push_back(x);
        used[x]++;
        cnt[a[x]]--;
        cur = x;
        st.erase(st.find(x));
      }
      continue;
    }
    long long x = a[now];
    if (used[x]) {
      ans.push_back(now);
      used[now]++;
      cnt[x]--;
      cur = now;
      st.erase(st.find(now));
    } else if (cnt[x] != n - 1 - ans.size()) {
      ans.push_back(now);
      used[now]++;
      cnt[x]--;
      cur = now;
      st.erase(st.find(now));
    } else {
      ans.push_back(x);
      used[x]++;
      cnt[a[x]]--;
      cur = x;
      st.erase(st.find(x));
    }
  }
  for (long long i = (0); i < ((n)); ++i) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
