'use strict';

function main(stdin) {
  const input = stdin.trim().split('\n').map(v => parseInt(v, 10));
  const N = input.shift();

  let first, second;
  first = second = -1;

  input.forEach(a => {
    if (a >= first) {
      second = first;
      first = a;
    } else if (a > second) {
      second = a;
    }
  });

  input.forEach(a => {
    if (a === first) console.log(second);
    else console.log(first);    
  });
}

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