"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const A = arg.slice(1, N + 1).map(n=>parseInt(n));
    const sorted = [...A].sort((a,b)=>b-a);
    
    const max = sorted[0];
    const second = sorted[1];
    
    for(let i in A) {
        if(max === A[i]) {
            console.log(second);
        } else {
            console.log(max);
        }
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));