import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  debug {
    enum n = 4;
    foreach (p; 0 .. n^^n) {
      auto ban = new int[n];
      foreach (i; 0 .. n) {
        ban[i] = p / n^^i % n;
      }
      auto perm = iota(n).array;
      bool found;
      do {
        bool ok = (perm[0] == 0);
        foreach (i; 0 .. n - 1) {
          ok = ok && (ban[perm[i]] != perm[i + 1]);
        }
        if (ok) {
          found = true;
          break;
        }
      } while (perm.nextPermutation);
      if (!found) {
        writeln(ban);
      }
    }
  }
  
  try {
    for (; ; ) {
      const N = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt() - 1;
      }
      
      if (N == 2) {
        writeln("-1");
        continue;
      }
      
      auto indeg = new int[N];
      alias Entry = Tuple!(int, "d", int, "v");
      BinaryHeap!(Array!Entry) que;
      foreach (u; 0 .. N) {
        ++indeg[A[u]];
      }
      foreach (v; 0 .. N) {
        que.insert(Entry(indeg[v], v));
      }
      
      auto unused = new RedBlackTree!int;
      foreach (u; 0 .. N) {
        unused.insert(u);
      }
      auto used = new bool[N];
      auto ans = new int[N];
      int last = -1;
      foreach (i; 0 .. N) {
        for (; used[que.front.v] || que.front.d > indeg[que.front.v]; que.removeFront) {}
        int u0 = -1;
        if (que.front.d == N - i - 1) {
          u0 = que.front.v;
        } else {
          foreach (u; unused) {
            if (last == -1 || A[last] != u) {
              u0 = u;
              break;
            }
          }
        }
        assert(u0 != -1);
        assert(last == -1 || A[last] != u0);
        --indeg[A[u0]];
        que.insert(Entry(indeg[A[u0]], A[u0]));
        unused.removeKey(u0);
        used[u0] = true;
        ans[i] = u0;
        last = u0;
      }
      
      foreach (i; 0 .. N) {
        if (i > 0) write(" ");
        write(ans[i] + 1);
      }
      writeln();
    }
  } catch (EOFException e) {
  }
}
