#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

#include "bits/stdc++.h"

template <typename Kty> struct _const_iterator {
private:
  using _map = std::map<Kty, size_t>;
  using _iterator = typename _map::const_iterator;
  _iterator _it;
  size_t cnt;

public:
  _const_iterator() : cnt(0) {}
  _const_iterator(_iterator it) : _it(it), cnt(0) {}
  _const_iterator(const _const_iterator &) = default;
  _const_iterator(_const_iterator &&) = default;
  _const_iterator &operator=(const _const_iterator &) = default;
  _const_iterator &operator=(_const_iterator &&) = default;

  using iterator_category = typename _iterator::iterator_category;
  using value_type = Kty;
  using difference_type = std::ptrdiff_t;
  using pointer = const value_type *;
  using reference = const value_type &;

  reference operator*() const { return _it->first; }

  pointer operator->() const { return &_it->first; }

private:
  void increment() {
    ++cnt;
    if (cnt == (*_it).second) {
      ++_it;
      cnt = 0;
    }
  }

  void decrement() {
    if (cnt > 0) {
      --cnt;
    } else {
      --_it;
      cnt = (*_it).second - 1;
    }
  }

public:
  _const_iterator &operator++() {
    increment();
    return *this;
  }

  _const_iterator operator++(int) {
    _const_iterator tmp = *this;
    increment();
    return tmp;
  }

  _const_iterator &operator--() {
    decrement();
    return *this;
  }

  _const_iterator operator--(int) {
    _const_iterator tmp = *this;
    decrement();
    return tmp;
  }

  bool operator==(const _const_iterator &rhs) const {
    return this->_it == rhs._it;
  }

  bool operator!=(const _const_iterator &rhs) const { return !(*this == rhs); }
};
template <typename Kt, class Ct = std::less<Kt>> class muitiset {
public:
  using key_type = Kt;
  using compare_type = Ct;

private:
  using _map = std::map<key_type, size_t, compare_type>;
  _map _count;

public:
  using const_iterator = _const_iterator<key_type>;
  using const_reverse_iterator =
      std::reverse_iterator<_const_iterator<key_type>>;

  const_iterator begin() const { return const_iterator(_count.begin()); }

  const_iterator end() const { return const_iterator(_count.end()); }

  const_reverse_iterator rbegin() const {
    return const_reverse_iterator(end());
  }

  const_reverse_iterator rend() const {
    return const_reverse_iterator(begin());
  }

  size_t count(const key_type &val) const noexcept {
    auto itr = _count.find(val);
    return itr == _count.end() ? 0 : itr->second;
  }

  void insert(const key_type &val) noexcept { _count[val]++; }

  void erase(const key_type &val) noexcept {
    if (_count.count(val) == 1) {
      if (--_count[val] == 0) {
        _count.erase(val);
      }
    }
  }

  void clear() noexcept { _count.clear(); }

  size_t size() const noexcept { return _count.size(); }

  const_iterator lower_bound(const key_type &val) const {
    return const_iterator(_count.lower_bound(val));
  }

  const_iterator upper_bound(const key_type &val) const {
    return const_iterator(_count.upper_bound(val));
  }

  const_reverse_iterator rlower_bound(const key_type &val) const {
    return const_reverse_iterator(upper_bound(val));
  }

  const_reverse_iterator rupper_bound(const key_type &val) const {
    return const_reverse_iterator(lower_bound(val));
  }

  const_iterator max_element() const {
    if (_count.empty()) {
      return end();
    }
    auto tmp = _count.end();
    tmp--;
    return const_iterator(tmp);
  }

  const_iterator min_element() const {
    if (_count.empty()) {
      return end();
    }
    return begin();
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi v(n);
  REP(i, n) cin >> v[i];
  REP(i, n) v[i]--;
  if (n <= 4) {
    vi p(n);
    REP(i, n) p[i] = i;
    do {
      bool ok = true;
      REP(i, n - 1) {
        if (v[p[i]] == p[i + 1])
          ok = false;
      }
      if (ok) {
        REP(i, n) { cout << p[i] + 1 << " "; }
        cout << endl;
        return 0;
      }
    } while (next_permutation(ALL(p)));
    cout << -1 << endl;
    return 0;
  }
  muitiset<int> mst;
  REP(i, n) mst.insert(v[i]);
  set<int> st;
  vi ans(n);
  REP(i, n) st.insert(i);

  REP(i, n - 4) {
    bool flag = false;
    if (mst.size() == 2) {
      if (mst.count(*next(mst.begin(), 1)) == n - 1 - i) {
        int a = *next(mst.begin(), 1);
        mst.erase(v[a]);
        if (mst.size() == 1 && st.count(a)) {
          flag = true;
          ans[i] = a;
          st.erase(a);
        }
        mst.insert(v[a]);
      }
      if (mst.count(*mst.begin()) == n - 1 - i) {
        int a = *mst.begin();
        mst.erase(v[a]);
        if (mst.size() == 1 && st.count(a)) {
          flag = true;
          ans[i] = a;
          st.erase(a);
        }
        mst.insert(v[a]);
      }

    }
    if (!flag) {
      int a = *st.begin();
      st.erase(a);
      mst.erase(v[a]);
      if (i > 0 && v[ans[i - 1]] == a) {
        int b = *st.begin();
        st.erase(b);
        mst.erase(v[b]);
        ans[i] = b;
        st.insert(a);
        mst.insert(v[a]);
      }
      else {
        ans[i] = a;
      }
    }

  }
  vi rem;
  REP(i, 4) {
    rem.push_back(*st.begin());
    st.erase(st.begin());
  }
  vi p(4);
  REP(i, 4) p[i] = i;
  do {
    bool ok = true;
    REP(i, 3) {
      if (v[rem[p[i]]] == rem[p[i + 1]])
        ok = false;
    }
    if (v[ans[n - 5]] == rem[p[0]])
      ok = false;
    if (ok) {
      REP(i, n - 4) cout << ans[i] + 1 << " ";
      REP(i, 4) cout << rem[p[i]] + 1 << " ";
      cout << endl;
      return 0;
    }

  } while (next_permutation(ALL(p)));
  abort();
}


Measured memory_bytes: 12544