use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read_<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read_().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: i32 = sc.read();
    let mut array: Vec<i32> = vec![];
    for _ in 0..n {
        array.push(sc.read());
    }

    let mut max = array.get(0).unwrap();
    let mut max_i = 0;
    for i in 1..n {
        if array.get(i as usize).unwrap() > max {
            max = array.get(i as usize).unwrap();
            max_i = i;
        }
    }

    let mut max_2 = array.get(0).unwrap();
    for i in 0..n {
        if i == max_i {
            continue;
        }

        if max_2 < array.get(i as usize).unwrap() {
            max_2 = array.get(i as usize).unwrap();
        }
    }

    for i in 0..n {
        if max_i == i {
            println!("{}", max_2);
        } else {
            println!("{}", max);
        }
    }
}