#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <cassert>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int LEN = 100000;

struct fastio{
  int it,len;
  char s[LEN + 5];
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush(){
    fwrite(s,1,it,stdout);
  }
}buff;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll(){
  char c; ll res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline char get_char(){
  char c;
  for(c = buff.get();c == ' ' || c == '\n';c = buff.get());
  return c;
}
#define maxn 100005
#define mp make_pair
int n,a[maxn],ban,in[maxn];
struct Heap_int{
  priority_queue < int,vector<int>,greater<int> > que,lazy;
  void push(int x){ que.push(x); }
  void pop(){
    while(lazy.size() && que.top() == lazy.top()) que.pop(), lazy.pop();
    que.pop();
  }
  void erase(int x){ lazy.push(x); }
  int top(){
    while(lazy.size() && que.top() == lazy.top()) que.pop(), lazy.pop();
    return que.top();
  }
  int top2(){
    int tmp = top(); pop();
    int ret = top(); push(tmp);
    return ret;
  }
  int size(){ return que.size() - lazy.size(); }
};
struct Heap_P{
  priority_queue <P> que,lazy;
  void push(P x){ que.push(x); }
  void pop(){
    while(lazy.size() && que.top() == lazy.top()) que.pop(), lazy.pop();
    que.pop();
  }
  void erase(P x){ lazy.push(x); }
  P top(){
    while(lazy.size() && que.top() == lazy.top()) que.pop(), lazy.pop();
    return que.top();
  }
  int size(){ return que.size() - lazy.size(); }
};
Heap_int hp;
Heap_P deg;
bool vis[maxn];
int fin_nxt(int r){ // there are r nodes left.
  P p = deg.top(); int u;
  if(p.first == r - 1){
    u = p.second;
  }else{
    u = hp.top();
    if(u == ban) u = hp.top2();
    if(r == 3){
      int v = 0, w = 0;
      for(int i = 1;i <= n;i++){
        if(u != i && !vis[i]){
          if(v) w = i;
          else v = i;
        }
      }
      if(a[v] == w && a[w] == v){
        if(ban == v) u = w;
        else u = v;
      }
    }
  }
  if(!vis[a[u]]){
    deg.erase(mp(in[a[u]],a[u]));
    in[a[u]]--;
    deg.push(mp(in[a[u]],a[u]));
  }
  vis[u] = true;
  hp.erase(u);
  deg.erase(mp(in[u],u));
  in[u] = 0;
  return u;
}
int main(){
  n = getint();
  for(int i = 1;i <= n;i++){
    a[i] = getint();
    in[a[i]]++;
  }
  if(n == 2){
    puts("-1");
    return 0;
  }
  for(int i = 1;i <= n;i++){
    hp.push(i);
    deg.push(mp(in[i],i));
  }
  for(int i = 1;i <= n;i++){
    int u = fin_nxt(n - i + 1);
    printf("%d%c",u,i == n ? '\n' : ' ');
    if(!vis[a[u]]) ban = a[u];
    else ban = 0;
  }
  return 0;
}