process.stdin.resume();
process.stdin.setEncoding('utf8');

var stdinLines = [];

var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  stdinLines.push(line);
});

reader.on('close', () => {
  const lines = stdinLines.slice(1, stdinLines.length).map(Number);
  if (lines.length === 1) {
    console.log(lines[0]);
    process.exit();
  }

  const sorted = Array.from(new Set(lines)).sort((a, b) => b - a);
  const max1 = sorted[0];
  const max2 = sorted[1];

  const eachMax = lines.map((v, i) => {
    if (v === max1) return max2;
    return max1;
  }).join("\n");

  console.log(eachMax);
});
