use std::collections::BinaryHeap;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();

    let a: Vec<usize> = (0..n).map(|_| sc.read::<usize>() - 1).collect();
    let mut ban_count = vec![0; n];
    for i in 0..n {
        ban_count[a[i]] += 1;
    }

    let mut ban_count_q = BinaryHeap::new();
    for i in 0..n {
        ban_count_q.push((ban_count[i], i));
    }
    let mut remain_q = BinaryHeap::new();
    for i in 0..n {
        remain_q.push(-(i as i64));
    }

    let mut used = vec![false; n];
    let mut ans = vec![];
    for _ in 0..n {
        let remain_size = remain_q.len();
        let mut candidate = vec![];
        while let Some((cur, i)) = ban_count_q.pop() {
            if used[i] {
            } else if cur != ban_count[i] {
                ban_count_q.push((ban_count[i], i));
            } else if ban_count[i] + 1 == remain_size {
                candidate.push(i);
            } else {
                assert!(ban_count[i] + 1 < remain_size);
                ban_count_q.push((ban_count[i], i));
                break;
            }
        }
        if candidate.len() > 1 {
            assert_eq!(remain_size, 2);
            if n == 2 {
                println!("-1");
                return;
            }

            let before = ans.pop().unwrap();
            if n == 3 {
                candidate.sort();
                ans.push(candidate[0]);
                ans.push(before);
                ans.push(candidate[1]);
                break;
            }
            assert!(n > 3);
            let prev = ans[ans.len() - 1];
            candidate.sort();
            if a[prev] == candidate[0] {
                ans.push(candidate[1]);
                ans.push(before);
                ans.push(candidate[0]);
            } else {
                ans.push(candidate[0]);
                ans.push(before);
                ans.push(candidate[1]);
            }
            break;
        }
        if candidate.is_empty() {
            let first = pop(&mut remain_q, &used);
            let can_select_first = ans.is_empty() || a[ans[ans.len() - 1]] != first;
            if can_select_first {
                push(first, &mut ans, &mut used, &mut ban_count, &a);
            } else {
                let second = pop(&mut remain_q, &used);
                push(second, &mut ans, &mut used, &mut ban_count, &a);
                remain_q.push(-(first as i64));
            }
        } else {
            let select = candidate[0];
            push(select, &mut ans, &mut used, &mut ban_count, &a);
        }
    }

    for i in 1..n {
        assert_ne!(a[ans[i - 1]], ans[i]);
    }

    for i in 0..n {
        if i > 0 {
            sc.write(" ");
        }
        sc.write(format!("{}", ans[i] + 1));
    }
    sc.write("\n");
}

fn last_fix(a: &Vec<usize>) {}

fn push(
    select: usize,
    ans: &mut Vec<usize>,
    used: &mut Vec<bool>,
    ban_count: &mut Vec<usize>,
    a: &Vec<usize>,
) {
    ans.push(select);
    used[select] = true;
    ban_count[a[select]] -= 1;
}

fn pop(q: &mut BinaryHeap<i64>, used: &Vec<bool>) -> usize {
    while let Some(x) = q.pop() {
        let i = (-x) as usize;
        if !used[i] {
            return i;
        }
    }
    unreachable!()
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 12540