'use strict'
const main = (input: string) => {
    // for-n1はTLE
    // sortして1番目と2番目出せればいい？
    const std: number[] = input.trim().split('\n').map(Number)
    const n: number = std.shift()
    const a: number[] = std
    const s: number[] = [...a].sort((a,b)=>a-b)
    let r: number[] = []
    for (let i = 0; i < n; i++) {
        if (a[i] === s[0]) {
            r.push(s[0])
        } else {
            r.push(s[1])
        }
    }
    console.log(r.join('\n'))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))
