'use strict';
function main(input) {
  const args = input.split('\n'),
        N = parseInt(args[0]),
        A = args.slice(1, N+1);
  let array = new Array();
  for (let a of A) {
    array.push(parseInt(a));
  }
  let max = 0;
  let maxIndex = 0;
  let maxNext = 0;
  for (let i = 0; i < N; ++i) {
    if (array[i] > max) {
      maxNext = max;
      max = array[i];
      maxIndex = i;
    } else if (array[i] > maxNext) {
      maxNext = array[i];
    }
  }
  for (let i = 0; i < N; ++i) {
    if (i === maxIndex) {
      console.log(maxNext);
    } else {
      console.log(max);
    }
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));