#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int N;
  while(cin >> N){
    vector<int> a(N); cin >> a;
    for(auto &x : a) x -= 1;

    if(N == 2){
      cout << -1 << endl;
    }else{

      vector<int> ans;

      vector<int> count(N);
      REP(i,N) count[a[i]] += 1;

      int cur = 0;

      REP(i,N){
        if(count[i] == N-1){
          cur = i;
          break;
        }
      }

      set<int> s;
      REP(i,N) s.insert(i);

      vector<set<int>> indeg(N);
      REP(i,N) indeg[count[i]].insert(i);

      while(not s.empty()){

        if(s.size() <= 5){
          vector<int> p;
          for(auto x : s) p.push_back(x);

          do{

            int c = cur;

            bool fail = false;

            for(auto x : p){
              if(a[c] == x){
                fail = true;
                break;
              }

              c = x;
            }


            if(not fail){
              for(auto &x : p) x += 1;
              ans.insert(ans.end(), ALL(p));

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

          break;
        }

        indeg[count[cur]].erase(cur);
        
        s.erase(cur);
        ans.push_back(cur+1);

        indeg[count[a[cur]]].erase(a[cur]);
        
        count[a[cur]] -= 1;

        indeg[count[a[cur]]].insert(a[cur]);


        if(indeg[(int)s.size()-1].size()){
          cur = *(indeg[(int)s.size()-1].begin());
        }else{
          int k = 0;
          ITR(it, s){
            if(k >= 5) break;
            ++k;

            if(*it == a[cur]) continue;

            cur = *it;
            break;
          }
        }
      }
      
      
      join(cout, ALL(ans));
      
    }
  }

  

  return 0;
}


Measured memory_bytes: 16128