import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			int u = ni();
			a[i] = u;
			b[i] = u;
		}

		Arrays.parallelSort(b);

		int max1 = b[n - 1];
		int max2 = b[n - 2];

		for (int i : a) {
			if (i == max1) {
				out(max2);
			} else if (i == max2) {
				out(max1);
			} else {
				out(max1);
			}
		}

	}

	/*
	 * 以下メソッド集
	 */

	public static void permutation(String q, String ans) {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	}

	static char[][] same(char[][] c, int h, int w) {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	}

	static int countkuro(char[][] c) {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	}

	static void debug() {

		out("---");
	}

	static void debug(Object a) {

		out("-------");
		out(a);
		out("-------");
	}

	static int ketasuu(int n) {

		String str = "" + n;
		return str.length();
	}

	static int account(String str) {

		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {

		return sc.nextInt();
	}

	static long nl() {

		return sc.nextLong();
	}

	static double nd() {

		return sc.nextDouble();
	}

	static String n() {

		return sc.next();
	}

	static char[] nc() {

		return sc.next().toCharArray();
	}

	static int kaijo(int n) {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(Object obj) {
		System.out.println(obj);
	}

	static void outn(Object obj) {
		System.out.print(obj);
	}

	static double max(double d, double e) {

		return Math.max(d, e);
	}

	static long max(long a, long b) {

		return Math.max(a, b);
	}

	static long min(long d, long e) {

		return Math.min(d, e);
	}

	static int min(int a, int b) {

		return Math.min(a, b);
	}
}

class XY {

	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			int u = ni();
			a[i] = u;
			b[i] = u;
		}

		Arrays.parallelSort(b);

		int max1 = b[n - 1];
		int max2 = b[n - 2];

		for (int i : a) {
			if (i == max1) {
				out(max2);
			} else if (i == max2) {
				out(max1);
			} else {
				out(max1);
			}
		}

	}

	/*
	 * 以下メソッド集
	 */

	public static void permutation(String q, String ans) {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	}

	static char[][] same(char[][] c, int h, int w) {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	}

	static int countkuro(char[][] c) {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	}

	static void debug() {

		out("---");
	}

	static void debug(Object a) {

		out("-------");
		out(a);
		out("-------");
	}

	static int ketasuu(int n) {

		String str = "" + n;
		return str.length();
	}

	static int account(String str) {

		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {

		return sc.nextInt();
	}

	static long nl() {

		return sc.nextLong();
	}

	static double nd() {

		return sc.nextDouble();
	}

	static String n() {

		return sc.next();
	}

	static char[] nc() {

		return sc.next().toCharArray();
	}

	static int kaijo(int n) {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(Object obj) {
		System.out.println(obj);
	}

	static void outn(Object obj) {
		System.out.print(obj);
	}

	static double max(double d, double e) {

		return Math.max(d, e);
	}

	static long max(long a, long b) {

		return Math.max(a, b);
	}

	static long min(long d, long e) {

		return Math.min(d, e);
	}

	static int min(int a, int b) {

		return Math.min(a, b);
	}
} Main public static String Y = "Yes"; Y "Yes" public static String N = "No"; N "No" public static long MOD = (long) (Math.pow(10, 9) + 7); MOD (long) (Math.pow(10, 9) + 7) Math.pow(10, 9) Math.pow Math 10 9 7 public static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {

		int n = ni();
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			int u = ni();
			a[i] = u;
			b[i] = u;
		}

		Arrays.parallelSort(b);

		int max1 = b[n - 1];
		int max2 = b[n - 2];

		for (int i : a) {
			if (i == max1) {
				out(max2);
			} else if (i == max2) {
				out(max1);
			} else {
				out(max1);
			}
		}

	} main {

		int n = ni();
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			int u = ni();
			a[i] = u;
			b[i] = u;
		}

		Arrays.parallelSort(b);

		int max1 = b[n - 1];
		int max2 = b[n - 2];

		for (int i : a) {
			if (i == max1) {
				out(max2);
			} else if (i == max2) {
				out(max1);
			} else {
				out(max1);
			}
		}

	} int n = ni(); n ni() ni int a[] = new int[n]; a new int[n] n int b[] = new int[n]; b new int[n] n for (int i = 0; i < n; i++) {
			int u = ni();
			a[i] = u;
			b[i] = u;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int u = ni();
			a[i] = u;
			b[i] = u;
		} {
			int u = ni();
			a[i] = u;
			b[i] = u;
		} int u = ni(); u ni() ni a[i] = u a[i] a i u b[i] = u b[i] b i u Arrays.parallelSort(b) Arrays.parallelSort Arrays b int max1 = b[n - 1]; max1 b[n - 1] b n - 1 n 1 int max2 = b[n - 2]; max2 b[n - 2] b n - 2 n 2 for (int i : a) {
			if (i == max1) {
				out(max2);
			} else if (i == max2) {
				out(max1);
			} else {
				out(max1);
			}
		} int i a {
			if (i == max1) {
				out(max2);
			} else if (i == max2) {
				out(max1);
			} else {
				out(max1);
			}
		} {
			if (i == max1) {
				out(max2);
			} else if (i == max2) {
				out(max1);
			} else {
				out(max1);
			}
		} if (i == max1) {
				out(max2);
			} else if (i == max2) {
				out(max1);
			} else {
				out(max1);
			} i == max1 i max1 {
				out(max2);
			} out(max2) out max2 if (i == max2) {
				out(max1);
			} else {
				out(max1);
			} i == max2 i max2 {
				out(max1);
			} out(max1) out max1 {
				out(max1);
			} out(max1) out max1 String[] args args public static void permutation(String q, String ans) {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	} permutation {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	} if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		} q.length() <= 1 q.length() q.length q 1 {
			System.out.println(ans + q);
		} System.out.println(ans + q) System.out.println System.out System System.out ans + q ans q {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		} for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			} int i = 0; int i = 0; i 0 i < q.length() i q.length() q.length q i++ i++ i {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			} {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			} permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i)) permutation q.substring(0, i) + q.substring(i + 1) q.substring(0, i) q.substring q 0 i q.substring(i + 1) q.substring q i + 1 i 1 ans + q.charAt(i) ans q.charAt(i) q.charAt q i String q q String ans ans static char[][] same(char[][] c, int h, int w) {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	} same {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	} char[][] a = new char[h][w]; a new char[h][w] h w for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		} int i = 0; int i = 0; i 0 i < h i h i++ i++ i {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		} {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		} for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			} int j = 0; int j = 0; j 0 j < w j w j++ j++ j {
				a[i][j] = c[i][j];
			} {
				a[i][j] = c[i][j];
			} a[i][j] = c[i][j] a[i][j] a[i] a i j c[i][j] c[i] c i j return a; a char[][] c c int h h int w w static int countkuro(char[][] c) {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	} countkuro {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	} int count = 0; count 0 for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		} char[] cc c {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		} {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		} for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			} char ccc cc {
				if ('#' == ccc) {
					count++;
				}
			} {
				if ('#' == ccc) {
					count++;
				}
			} if ('#' == ccc) {
					count++;
				} '#' == ccc '#' ccc {
					count++;
				} count++ count return count; count char[][] c c static void debug() {

		out("---");
	} debug {

		out("---");
	} out("---") out "---" static void debug(Object a) {

		out("-------");
		out(a);
		out("-------");
	} debug {

		out("-------");
		out(a);
		out("-------");
	} out("-------") out "-------" out(a) out a out("-------") out "-------" Object a a static int ketasuu(int n) {

		String str = "" + n;
		return str.length();
	} ketasuu {

		String str = "" + n;
		return str.length();
	} String str = "" + n; str "" + n "" n return str.length(); str.length() str.length str int n n static int account(String str) {

		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	} account {

		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	} String target = "AC"; target "AC" int count = 0; count 0 int len = str.length(); len str.length() str.length str for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		} int i = 0; int i = 0; i 0 i < len - 1 i len - 1 len 1 i++ i++ i {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		} {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		} if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			} target.equals(str.substring(i, i + target.length())) target.equals target str.substring(i, i + target.length()) str.substring str i i + target.length() i target.length() target.length target {
				count++;
			} count++ count return count; count String str str static int ni() {

		return sc.nextInt();
	} ni {

		return sc.nextInt();
	} return sc.nextInt(); sc.nextInt() sc.nextInt sc static long nl() {

		return sc.nextLong();
	} nl {

		return sc.nextLong();
	} return sc.nextLong(); sc.nextLong() sc.nextLong sc static double nd() {

		return sc.nextDouble();
	} nd {

		return sc.nextDouble();
	} return sc.nextDouble(); sc.nextDouble() sc.nextDouble sc static String n() {

		return sc.next();
	} n {

		return sc.next();
	} return sc.next(); sc.next() sc.next sc static char[] nc() {

		return sc.next().toCharArray();
	} nc {

		return sc.next().toCharArray();
	} return sc.next().toCharArray(); sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc static int kaijo(int n) {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	} kaijo {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	} if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		} n == 0 || n == 1 n == 0 n 0 n == 1 n 1 {
			return 1;
		} return 1; 1 {
			return n * kaijo(n - 1);
		} return n * kaijo(n - 1); n * kaijo(n - 1) n kaijo(n - 1) kaijo n - 1 n 1 int n n static int fib(int n) {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	} fib {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	} return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1); (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1) (n == 1 || n == 0) n == 1 n 1 n == 0 n 0 n fib(n - 2) + fib(n - 1) fib(n - 2) fib n - 2 n 2 fib(n - 1) fib n - 1 n 1 int n n static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	} lcm {

		return m * n / gcd(m, n);
	} return m * n / gcd(m, n); m * n / gcd(m, n) m * n m n gcd(m, n) gcd m n long m m long n n static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	} lcm {

		return m * n / gcd(m, n);
	} return m * n / gcd(m, n); m * n / gcd(m, n) m * n m n gcd(m, n) gcd m n int m m int n n static long gcd(long a, long b) {

		return (b == 0) ? a : gcd(b, a % b);
	} gcd {

		return (b == 0) ? a : gcd(b, a % b);
	} return (b == 0) ? a : gcd(b, a % b); (b == 0) ? a : gcd(b, a % b) (b == 0) b 0 a gcd(b, a % b) gcd b a % b a b long a a long b b static int gcd(int a, int b) {

		return (b == 0) ? a : gcd(b, a % b);
	} gcd {

		return (b == 0) ? a : gcd(b, a % b);
	} return (b == 0) ? a : gcd(b, a % b); (b == 0) ? a : gcd(b, a % b) (b == 0) b 0 a gcd(b, a % b) gcd b a % b a b int a a int b b static void out(Object obj) {
		System.out.println(obj);
	} out {
		System.out.println(obj);
	} System.out.println(obj) System.out.println System.out System System.out obj Object obj obj static void outn(Object obj) {
		System.out.print(obj);
	} outn {
		System.out.print(obj);
	} System.out.print(obj) System.out.print System.out System System.out obj Object obj obj static double max(double d, double e) {

		return Math.max(d, e);
	} max {

		return Math.max(d, e);
	} return Math.max(d, e); Math.max(d, e) Math.max Math d e double d d double e e static long max(long a, long b) {

		return Math.max(a, b);
	} max {

		return Math.max(a, b);
	} return Math.max(a, b); Math.max(a, b) Math.max Math a b long a a long b b static long min(long d, long e) {

		return Math.min(d, e);
	} min {

		return Math.min(d, e);
	} return Math.min(d, e); Math.min(d, e) Math.min Math d e long d d long e e static int min(int a, int b) {

		return Math.min(a, b);
	} min {

		return Math.min(a, b);
	} return Math.min(a, b); Math.min(a, b) Math.min Math a b int a a int b b class XY {

	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
} XY int h; h int c; c XY(int h, int c) {
		this.h = h;
		this.c = c;
	} XY {
		this.h = h;
		this.c = c;
	} this.h = h this.h this this.h h this.c = c this.c this this.c c int h h int c c public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			int u = ni();
			a[i] = u;
			b[i] = u;
		}

		Arrays.parallelSort(b);

		int max1 = b[n - 1];
		int max2 = b[n - 2];

		for (int i : a) {
			if (i == max1) {
				out(max2);
			} else if (i == max2) {
				out(max1);
			} else {
				out(max1);
			}
		}

	}

	/*
	 * 以下メソッド集
	 */

	public static void permutation(String q, String ans) {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	}

	static char[][] same(char[][] c, int h, int w) {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	}

	static int countkuro(char[][] c) {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	}

	static void debug() {

		out("---");
	}

	static void debug(Object a) {

		out("-------");
		out(a);
		out("-------");
	}

	static int ketasuu(int n) {

		String str = "" + n;
		return str.length();
	}

	static int account(String str) {

		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {

		return sc.nextInt();
	}

	static long nl() {

		return sc.nextLong();
	}

	static double nd() {

		return sc.nextDouble();
	}

	static String n() {

		return sc.next();
	}

	static char[] nc() {

		return sc.next().toCharArray();
	}

	static int kaijo(int n) {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(Object obj) {
		System.out.println(obj);
	}

	static void outn(Object obj) {
		System.out.print(obj);
	}

	static double max(double d, double e) {

		return Math.max(d, e);
	}

	static long max(long a, long b) {

		return Math.max(a, b);
	}

	static long min(long d, long e) {

		return Math.min(d, e);
	}

	static int min(int a, int b) {

		return Math.min(a, b);
	}
} public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			int u = ni();
			a[i] = u;
			b[i] = u;
		}

		Arrays.parallelSort(b);

		int max1 = b[n - 1];
		int max2 = b[n - 2];

		for (int i : a) {
			if (i == max1) {
				out(max2);
			} else if (i == max2) {
				out(max1);
			} else {
				out(max1);
			}
		}

	}

	/*
	 * 以下メソッド集
	 */

	public static void permutation(String q, String ans) {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	}

	static char[][] same(char[][] c, int h, int w) {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	}

	static int countkuro(char[][] c) {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	}

	static void debug() {

		out("---");
	}

	static void debug(Object a) {

		out("-------");
		out(a);
		out("-------");
	}

	static int ketasuu(int n) {

		String str = "" + n;
		return str.length();
	}

	static int account(String str) {

		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {

		return sc.nextInt();
	}

	static long nl() {

		return sc.nextLong();
	}

	static double nd() {

		return sc.nextDouble();
	}

	static String n() {

		return sc.next();
	}

	static char[] nc() {

		return sc.next().toCharArray();
	}

	static int kaijo(int n) {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(Object obj) {
		System.out.println(obj);
	}

	static void outn(Object obj) {
		System.out.print(obj);
	}

	static double max(double d, double e) {

		return Math.max(d, e);
	}

	static long max(long a, long b) {

		return Math.max(a, b);
	}

	static long min(long d, long e) {

		return Math.min(d, e);
	}

	static int min(int a, int b) {

		return Math.min(a, b);
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			int u = ni();
			a[i] = u;
			b[i] = u;
		}

		Arrays.parallelSort(b);

		int max1 = b[n - 1];
		int max2 = b[n - 2];

		for (int i : a) {
			if (i == max1) {
				out(max2);
			} else if (i == max2) {
				out(max1);
			} else {
				out(max1);
			}
		}

	}

	/*
	 * 以下メソッド集
	 */

	public static void permutation(String q, String ans) {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	}

	static char[][] same(char[][] c, int h, int w) {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	}

	static int countkuro(char[][] c) {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	}

	static void debug() {

		out("---");
	}

	static void debug(Object a) {

		out("-------");
		out(a);
		out("-------");
	}

	static int ketasuu(int n) {

		String str = "" + n;
		return str.length();
	}

	static int account(String str) {

		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {

		return sc.nextInt();
	}

	static long nl() {

		return sc.nextLong();
	}

	static double nd() {

		return sc.nextDouble();
	}

	static String n() {

		return sc.next();
	}

	static char[] nc() {

		return sc.next().toCharArray();
	}

	static int kaijo(int n) {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(Object obj) {
		System.out.println(obj);
	}

	static void outn(Object obj) {
		System.out.print(obj);
	}

	static double max(double d, double e) {

		return Math.max(d, e);
	}

	static long max(long a, long b) {

		return Math.max(a, b);
	}

	static long min(long d, long e) {

		return Math.min(d, e);
	}

	static int min(int a, int b) {

		return Math.min(a, b);
	}
}

class XY {

	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}
