function Main(input) {
  var dataList = input.split("\n");
  dataList.shift();
  dataList.pop();
  var max1 = -1;
  var max1IndexList = [];
  var max2 = -1;
  var max21IndexList = [];
  for (var i = 0; i < dataList.length; i++) {
    dataList[i] = Number(dataList[i]);
    if (max1 < dataList[i]) {
      max2 = max1;
      max1 = dataList[i];
    }
  }
  for (var i = 0; i < dataList.length; i++) {
    if (max1 === dataList[i]) max1IndexList.push(i);
    if (max2 === dataList[i]) max21IndexList.push(i);    
  }
  if (max1IndexList.length > 1) {
    for (var i = 0; i < dataList.length; i++) {
      console.log(max1);
    }
  } else {
    for (var i = 0; i < dataList.length; i++) {
      if (max1 === dataList[i]) {
        console.log(max2);
      } else {
        console.log(max1);
      }
    }    
  }
  function gatMax(excludeIndex) {
    var max = -1;
    for (var i = 0; i < dataList.length; i++) {
      if (excludeIndex === i) continue;
      if (max === -1) max = dataList[i];
      if (dataList[i] > max) max = dataList[i];
    }  
    return max;
  }  
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));