#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <cassert>
#include <complex>
#include <functional>
 
using namespace std;
 
typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    --a[i];
  }
  if (n == 2) {
    cout << "-1\n";
    return 0;
  }
  vector <int> hate(n);
  for (int i = 0; i < n; ++i) ++hate[a[i]];
  set <int> have;
  for (int i = 0; i < n; ++i) have.insert(i);
  vector <int> ans;
  vector <bool> used(n);
  int who = -1;
  for (int i = 0; i < n; ++i) {
    for (int j : have) {
      if (j == who) continue;
      int x = a[j];
      if (!used[x] && hate[x] == n - i - 1) {
        continue;
      }
      ans.push_back(j);
      used[j] = 1;
      --hate[x];
      who = x;
      break;
    }
    have.erase(ans.back());
    if (n - i - 1 <= 6) break;
  }
  vector <int> cur;
  for (int j : have) cur.push_back(j);
  vector <int> best;
  do {
    if (cur.front() == who) continue;
    bool bad = false;
    for (int i = 0; i + 1 < (int)cur.size(); ++i) {
      if (cur[i + 1] == a[cur[i]]) {
        bad = true;
        break;
      }
    }
    if (!bad) {
      if (best.empty() || cur < best) best = cur;
    }
  } while (next_permutation(cur.begin(), cur.end()));

  for (int x : ans) {
    cout << x + 1 << ' ';
  }
  for (int x : best) {
    cout << x + 1 << ' ';
  }
}
