import java.util.Scanner;

public class Main{

  public static void main (String[] args){

    Scanner sc = new Scanner (System.in);

    int N = sc.nextInt();
    
    int[] list = new int [N];
    int maxNum = 0;
    int nextMaxNum = 0;
    int maxIndex = 0;
    
    for (int index=0; index<N; index++){
      int temp = sc.nextInt();
      list [index] = temp;
      if (maxNum<temp){
        maxNum=temp;
        maxIndex=index;
      } else if (nextMaxNum<temp){
        nextMaxNum=temp;
      }
    }
    
    for (int index=0; index<N; index++){
      if (index==maxIndex){
        System.out.println(nextMaxNum);
      } else {
        System.out.println(maxNum);
      }
    }
  }
} import java.util.Scanner; Scanner java.util public class Main{

  public static void main (String[] args){

    Scanner sc = new Scanner (System.in);

    int N = sc.nextInt();
    
    int[] list = new int [N];
    int maxNum = 0;
    int nextMaxNum = 0;
    int maxIndex = 0;
    
    for (int index=0; index<N; index++){
      int temp = sc.nextInt();
      list [index] = temp;
      if (maxNum<temp){
        maxNum=temp;
        maxIndex=index;
      } else if (nextMaxNum<temp){
        nextMaxNum=temp;
      }
    }
    
    for (int index=0; index<N; index++){
      if (index==maxIndex){
        System.out.println(nextMaxNum);
      } else {
        System.out.println(maxNum);
      }
    }
  }
} Main public static void main (String[] args){

    Scanner sc = new Scanner (System.in);

    int N = sc.nextInt();
    
    int[] list = new int [N];
    int maxNum = 0;
    int nextMaxNum = 0;
    int maxIndex = 0;
    
    for (int index=0; index<N; index++){
      int temp = sc.nextInt();
      list [index] = temp;
      if (maxNum<temp){
        maxNum=temp;
        maxIndex=index;
      } else if (nextMaxNum<temp){
        nextMaxNum=temp;
      }
    }
    
    for (int index=0; index<N; index++){
      if (index==maxIndex){
        System.out.println(nextMaxNum);
      } else {
        System.out.println(maxNum);
      }
    }
  } main {

    Scanner sc = new Scanner (System.in);

    int N = sc.nextInt();
    
    int[] list = new int [N];
    int maxNum = 0;
    int nextMaxNum = 0;
    int maxIndex = 0;
    
    for (int index=0; index<N; index++){
      int temp = sc.nextInt();
      list [index] = temp;
      if (maxNum<temp){
        maxNum=temp;
        maxIndex=index;
      } else if (nextMaxNum<temp){
        nextMaxNum=temp;
      }
    }
    
    for (int index=0; index<N; index++){
      if (index==maxIndex){
        System.out.println(nextMaxNum);
      } else {
        System.out.println(maxNum);
      }
    }
  } Scanner sc = new Scanner (System.in); sc new Scanner (System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] list = new int [N]; list new int [N] N int maxNum = 0; maxNum 0 int nextMaxNum = 0; nextMaxNum 0 int maxIndex = 0; maxIndex 0 for (int index=0; index<N; index++){
      int temp = sc.nextInt();
      list [index] = temp;
      if (maxNum<temp){
        maxNum=temp;
        maxIndex=index;
      } else if (nextMaxNum<temp){
        nextMaxNum=temp;
      }
    } int index=0; int index=0; index 0 index<N index N index++ index++ index {
      int temp = sc.nextInt();
      list [index] = temp;
      if (maxNum<temp){
        maxNum=temp;
        maxIndex=index;
      } else if (nextMaxNum<temp){
        nextMaxNum=temp;
      }
    } {
      int temp = sc.nextInt();
      list [index] = temp;
      if (maxNum<temp){
        maxNum=temp;
        maxIndex=index;
      } else if (nextMaxNum<temp){
        nextMaxNum=temp;
      }
    } int temp = sc.nextInt(); temp sc.nextInt() sc.nextInt sc list [index] = temp list [index] list index temp if (maxNum<temp){
        maxNum=temp;
        maxIndex=index;
      } else if (nextMaxNum<temp){
        nextMaxNum=temp;
      } maxNum<temp maxNum temp {
        maxNum=temp;
        maxIndex=index;
      } maxNum=temp maxNum temp maxIndex=index maxIndex index if (nextMaxNum<temp){
        nextMaxNum=temp;
      } nextMaxNum<temp nextMaxNum temp {
        nextMaxNum=temp;
      } nextMaxNum=temp nextMaxNum temp for (int index=0; index<N; index++){
      if (index==maxIndex){
        System.out.println(nextMaxNum);
      } else {
        System.out.println(maxNum);
      }
    } int index=0; int index=0; index 0 index<N index N index++ index++ index {
      if (index==maxIndex){
        System.out.println(nextMaxNum);
      } else {
        System.out.println(maxNum);
      }
    } {
      if (index==maxIndex){
        System.out.println(nextMaxNum);
      } else {
        System.out.println(maxNum);
      }
    } if (index==maxIndex){
        System.out.println(nextMaxNum);
      } else {
        System.out.println(maxNum);
      } index==maxIndex index maxIndex {
        System.out.println(nextMaxNum);
      } System.out.println(nextMaxNum) System.out.println System.out System System.out nextMaxNum {
        System.out.println(maxNum);
      } System.out.println(maxNum) System.out.println System.out System System.out maxNum String[] args args public class Main{

  public static void main (String[] args){

    Scanner sc = new Scanner (System.in);

    int N = sc.nextInt();
    
    int[] list = new int [N];
    int maxNum = 0;
    int nextMaxNum = 0;
    int maxIndex = 0;
    
    for (int index=0; index<N; index++){
      int temp = sc.nextInt();
      list [index] = temp;
      if (maxNum<temp){
        maxNum=temp;
        maxIndex=index;
      } else if (nextMaxNum<temp){
        nextMaxNum=temp;
      }
    }
    
    for (int index=0; index<N; index++){
      if (index==maxIndex){
        System.out.println(nextMaxNum);
      } else {
        System.out.println(maxNum);
      }
    }
  }
} public class Main{

  public static void main (String[] args){

    Scanner sc = new Scanner (System.in);

    int N = sc.nextInt();
    
    int[] list = new int [N];
    int maxNum = 0;
    int nextMaxNum = 0;
    int maxIndex = 0;
    
    for (int index=0; index<N; index++){
      int temp = sc.nextInt();
      list [index] = temp;
      if (maxNum<temp){
        maxNum=temp;
        maxIndex=index;
      } else if (nextMaxNum<temp){
        nextMaxNum=temp;
      }
    }
    
    for (int index=0; index<N; index++){
      if (index==maxIndex){
        System.out.println(nextMaxNum);
      } else {
        System.out.println(maxNum);
      }
    }
  }
} Main
import java.util.Scanner;

public class Main{

  public static void main (String[] args){

    Scanner sc = new Scanner (System.in);

    int N = sc.nextInt();
    
    int[] list = new int [N];
    int maxNum = 0;
    int nextMaxNum = 0;
    int maxIndex = 0;
    
    for (int index=0; index<N; index++){
      int temp = sc.nextInt();
      list [index] = temp;
      if (maxNum<temp){
        maxNum=temp;
        maxIndex=index;
      } else if (nextMaxNum<temp){
        nextMaxNum=temp;
      }
    }
    
    for (int index=0; index<N; index++){
      if (index==maxIndex){
        System.out.println(nextMaxNum);
      } else {
        System.out.println(maxNum);
      }
    }
  }
}