#include<bits/stdc++.h>

using namespace std;

#define pb push_back
const int maxi = 1e6 + 10;
int a[maxi];
string s;
int n;
int p[maxi];
int cnt[maxi];
set<pair<int,int>> st;
set<int> st1;
int ob[maxi];
int ans[maxi];
vector<int> v[maxi];

int lex()
{
    if (ans[1]==0) return 1;

    for (int i=1;i<=n;i++)
        if (ans[i]>p[i]) return 1; else
            if (ans[i]<p[i]) return 0;
    return 0;
}
int main()
{
    cin>>n;

    for (int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        cnt[a[i]]++;
        v[a[i]].pb(i);
    }


   for (int i=1;i<=n;i++)
   {
       st.insert({-cnt[i], i});
       st1.insert(i);
   }

   int cur = 0;
   int pr = 0;

   if (n==2) return !printf("-1\n");

   while(!st1.empty())
   {
       pair<int,int> node = *st.begin();
       if (-node.first == n - cur - 1)
       {
           p[++cur]  = node.second;
           st.erase(node);
           st1.erase(node.second);
       } else
       {
           int node1 = *st1.begin();
           st1.erase(node1);
           int node2 = 0;

           if (a[pr] ==  node1)
           {
              if (!st1.empty()){
              int node2 = *st1.begin();
              st1.erase(node2);
              st1.insert(node1);
              node1 = node2;
           }
          }

           p[++cur] = node1;
           st.erase({-cnt[node1], node1});
       }

       ob[p[cur]] = 1;

      if (!ob[a[p[cur]]])
      {
          st.erase({-cnt[a[p[cur]]], a[p[cur]]});
          cnt[a[p[cur]]]--;
          st.insert({-cnt[a[p[cur]]], a[p[cur]]});
      }

      pr = p[cur];
   }

   do
   {
       int ok = 1;
      for (int i=1;i<n;i++)
        if (p[i+1] == a[p[i]]) ok = 0;

     if (lex() && ok)
     {
         for (int i=1;i<=n;i++)
            ans[i] = p[i];
     }

   } while(next_permutation(p+n-2, p+n+1));

    for (int i=1;i<=n;i++)
        printf("%d ",ans[i]);

    return 0;
}
//A ja bih se s tobom topila,
//al ne bih ti to priznala,
//da nisam popila.
//A ti,bas je dobro sto si tu,
//daj slobodno pokazi mi,
//taj skriveni tattoo.
