import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //String[] s1 = sc.nextLine().split(" ");

        int n = Integer.parseInt(sc.nextLine());
        String[] s1 = new String[n];
        int[] intS1 = new int[n];

        int max1=0;
        int max2=0;
        for (int i = 0;i < s1.length;i++) {
        	intS1[i]=Integer.parseInt(sc.nextLine());
        	if (max1<=intS1[i]) {
        		max2=max1;
        		max1=intS1[i];
        	} else if (max2<=intS1[i]) {
        		max2=intS1[i];
        	}
        }

        for (int i = 0;i < s1.length;i++) {
        	if (intS1[i]==max1) {
        		System.out.println(max2);
        	} else {
        		System.out.println(max1);
        	}
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //String[] s1 = sc.nextLine().split(" ");

        int n = Integer.parseInt(sc.nextLine());
        String[] s1 = new String[n];
        int[] intS1 = new int[n];

        int max1=0;
        int max2=0;
        for (int i = 0;i < s1.length;i++) {
        	intS1[i]=Integer.parseInt(sc.nextLine());
        	if (max1<=intS1[i]) {
        		max2=max1;
        		max1=intS1[i];
        	} else if (max2<=intS1[i]) {
        		max2=intS1[i];
        	}
        }

        for (int i = 0;i < s1.length;i++) {
        	if (intS1[i]==max1) {
        		System.out.println(max2);
        	} else {
        		System.out.println(max1);
        	}
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //String[] s1 = sc.nextLine().split(" ");

        int n = Integer.parseInt(sc.nextLine());
        String[] s1 = new String[n];
        int[] intS1 = new int[n];

        int max1=0;
        int max2=0;
        for (int i = 0;i < s1.length;i++) {
        	intS1[i]=Integer.parseInt(sc.nextLine());
        	if (max1<=intS1[i]) {
        		max2=max1;
        		max1=intS1[i];
        	} else if (max2<=intS1[i]) {
        		max2=intS1[i];
        	}
        }

        for (int i = 0;i < s1.length;i++) {
        	if (intS1[i]==max1) {
        		System.out.println(max2);
        	} else {
        		System.out.println(max1);
        	}
        }
    } main {
        Scanner sc = new Scanner(System.in);
        //String[] s1 = sc.nextLine().split(" ");

        int n = Integer.parseInt(sc.nextLine());
        String[] s1 = new String[n];
        int[] intS1 = new int[n];

        int max1=0;
        int max2=0;
        for (int i = 0;i < s1.length;i++) {
        	intS1[i]=Integer.parseInt(sc.nextLine());
        	if (max1<=intS1[i]) {
        		max2=max1;
        		max1=intS1[i];
        	} else if (max2<=intS1[i]) {
        		max2=intS1[i];
        	}
        }

        for (int i = 0;i < s1.length;i++) {
        	if (intS1[i]==max1) {
        		System.out.println(max2);
        	} else {
        		System.out.println(max1);
        	}
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.nextLine()); n Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc String[] s1 = new String[n]; s1 new String[n] n int[] intS1 = new int[n]; intS1 new int[n] n int max1=0; max1 0 int max2=0; max2 0 for (int i = 0;i < s1.length;i++) {
        	intS1[i]=Integer.parseInt(sc.nextLine());
        	if (max1<=intS1[i]) {
        		max2=max1;
        		max1=intS1[i];
        	} else if (max2<=intS1[i]) {
        		max2=intS1[i];
        	}
        } int i = 0; int i = 0; i 0 i < s1.length i s1.length s1 s1.length i++ i++ i {
        	intS1[i]=Integer.parseInt(sc.nextLine());
        	if (max1<=intS1[i]) {
        		max2=max1;
        		max1=intS1[i];
        	} else if (max2<=intS1[i]) {
        		max2=intS1[i];
        	}
        } {
        	intS1[i]=Integer.parseInt(sc.nextLine());
        	if (max1<=intS1[i]) {
        		max2=max1;
        		max1=intS1[i];
        	} else if (max2<=intS1[i]) {
        		max2=intS1[i];
        	}
        } intS1[i]=Integer.parseInt(sc.nextLine()) intS1[i] intS1 i Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc if (max1<=intS1[i]) {
        		max2=max1;
        		max1=intS1[i];
        	} else if (max2<=intS1[i]) {
        		max2=intS1[i];
        	} max1<=intS1[i] max1 intS1[i] intS1 i {
        		max2=max1;
        		max1=intS1[i];
        	} max2=max1 max2 max1 max1=intS1[i] max1 intS1[i] intS1 i if (max2<=intS1[i]) {
        		max2=intS1[i];
        	} max2<=intS1[i] max2 intS1[i] intS1 i {
        		max2=intS1[i];
        	} max2=intS1[i] max2 intS1[i] intS1 i for (int i = 0;i < s1.length;i++) {
        	if (intS1[i]==max1) {
        		System.out.println(max2);
        	} else {
        		System.out.println(max1);
        	}
        } int i = 0; int i = 0; i 0 i < s1.length i s1.length s1 s1.length i++ i++ i {
        	if (intS1[i]==max1) {
        		System.out.println(max2);
        	} else {
        		System.out.println(max1);
        	}
        } {
        	if (intS1[i]==max1) {
        		System.out.println(max2);
        	} else {
        		System.out.println(max1);
        	}
        } if (intS1[i]==max1) {
        		System.out.println(max2);
        	} else {
        		System.out.println(max1);
        	} intS1[i]==max1 intS1[i] intS1 i max1 {
        		System.out.println(max2);
        	} System.out.println(max2) System.out.println System.out System System.out max2 {
        		System.out.println(max1);
        	} System.out.println(max1) System.out.println System.out System System.out max1 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //String[] s1 = sc.nextLine().split(" ");

        int n = Integer.parseInt(sc.nextLine());
        String[] s1 = new String[n];
        int[] intS1 = new int[n];

        int max1=0;
        int max2=0;
        for (int i = 0;i < s1.length;i++) {
        	intS1[i]=Integer.parseInt(sc.nextLine());
        	if (max1<=intS1[i]) {
        		max2=max1;
        		max1=intS1[i];
        	} else if (max2<=intS1[i]) {
        		max2=intS1[i];
        	}
        }

        for (int i = 0;i < s1.length;i++) {
        	if (intS1[i]==max1) {
        		System.out.println(max2);
        	} else {
        		System.out.println(max1);
        	}
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //String[] s1 = sc.nextLine().split(" ");

        int n = Integer.parseInt(sc.nextLine());
        String[] s1 = new String[n];
        int[] intS1 = new int[n];

        int max1=0;
        int max2=0;
        for (int i = 0;i < s1.length;i++) {
        	intS1[i]=Integer.parseInt(sc.nextLine());
        	if (max1<=intS1[i]) {
        		max2=max1;
        		max1=intS1[i];
        	} else if (max2<=intS1[i]) {
        		max2=intS1[i];
        	}
        }

        for (int i = 0;i < s1.length;i++) {
        	if (intS1[i]==max1) {
        		System.out.println(max2);
        	} else {
        		System.out.println(max1);
        	}
        }
    }
} Main
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //String[] s1 = sc.nextLine().split(" ");

        int n = Integer.parseInt(sc.nextLine());
        String[] s1 = new String[n];
        int[] intS1 = new int[n];

        int max1=0;
        int max2=0;
        for (int i = 0;i < s1.length;i++) {
        	intS1[i]=Integer.parseInt(sc.nextLine());
        	if (max1<=intS1[i]) {
        		max2=max1;
        		max1=intS1[i];
        	} else if (max2<=intS1[i]) {
        		max2=intS1[i];
        	}
        }

        for (int i = 0;i < s1.length;i++) {
        	if (intS1[i]==max1) {
        		System.out.println(max2);
        	} else {
        		System.out.println(max1);
        	}
        }
    }
}