import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		A = new int[N];
	}

	public boolean hasNext() {
		return cnt < N;
	}

	int[] A;
	int First = 1;
	int Second = 1;

	public void readBody(String str) {
		// System.out.println(str);
		int a = Integer.parseInt(str);
		A[cnt] = a;
		if (First < a)
			First = a;
		else if (Second < a)
			Second = a;
		cnt++;
	}

	public void solve() {
		for (int i = 0; i < N; i++) {
			if (A[i] == First)
				System.out.println(Second);
			else
				System.out.println(First);
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
} Main public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	} main {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	} BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) Solver solver = new Solver(); solver new Solver() solver.init() solver.init solver solver.readHead(in.readLine()) solver.readHead solver in.readLine() in.readLine in for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		} ; solver.hasNext() solver.hasNext solver {
			solver.readBody(in.readLine());
		} {
			solver.readBody(in.readLine());
		} solver.readBody(in.readLine()) solver.readBody solver in.readLine() in.readLine in solver.solve() solver.solve solver String args[] args class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		A = new int[N];
	}

	public boolean hasNext() {
		return cnt < N;
	}

	int[] A;
	int First = 1;
	int Second = 1;

	public void readBody(String str) {
		// System.out.println(str);
		int a = Integer.parseInt(str);
		A[cnt] = a;
		if (First < a)
			First = a;
		else if (Second < a)
			Second = a;
		cnt++;
	}

	public void solve() {
		for (int i = 0; i < N; i++) {
			if (A[i] == First)
				System.out.println(Second);
			else
				System.out.println(First);
		}
	}
} Solver int N; N int cnt; cnt int[] A; A int First = 1; First 1 int Second = 1; Second 1 public void init() {
		N = 0;
		cnt = 0;
	} init {
		N = 0;
		cnt = 0;
	} N = 0 N 0 cnt = 0 cnt 0 public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		A = new int[N];
	} readHead {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		A = new int[N];
	} String[] strArr = str.split("\\s+"); strArr str.split("\\s+") str.split str "\\s+" N = Integer.parseInt(strArr[0]) N Integer.parseInt(strArr[0]) Integer.parseInt Integer strArr[0] strArr 0 A = new int[N] A new int[N] N String str str public boolean hasNext() {
		return cnt < N;
	} hasNext {
		return cnt < N;
	} return cnt < N; cnt < N cnt N public void readBody(String str) {
		// System.out.println(str);
		int a = Integer.parseInt(str);
		A[cnt] = a;
		if (First < a)
			First = a;
		else if (Second < a)
			Second = a;
		cnt++;
	} readBody {
		// System.out.println(str);
		int a = Integer.parseInt(str);
		A[cnt] = a;
		if (First < a)
			First = a;
		else if (Second < a)
			Second = a;
		cnt++;
	} int a = Integer.parseInt(str); a Integer.parseInt(str) Integer.parseInt Integer str A[cnt] = a A[cnt] A cnt a if (First < a)
			First = a;
		else if (Second < a)
			Second = a; First < a First a First = a First a if (Second < a)
			Second = a; Second < a Second a Second = a Second a cnt++ cnt String str str public void solve() {
		for (int i = 0; i < N; i++) {
			if (A[i] == First)
				System.out.println(Second);
			else
				System.out.println(First);
		}
	} solve {
		for (int i = 0; i < N; i++) {
			if (A[i] == First)
				System.out.println(Second);
			else
				System.out.println(First);
		}
	} for (int i = 0; i < N; i++) {
			if (A[i] == First)
				System.out.println(Second);
			else
				System.out.println(First);
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if (A[i] == First)
				System.out.println(Second);
			else
				System.out.println(First);
		} {
			if (A[i] == First)
				System.out.println(Second);
			else
				System.out.println(First);
		} if (A[i] == First)
				System.out.println(Second);
			else
				System.out.println(First); A[i] == First A[i] A i First System.out.println(Second) System.out.println System.out System System.out Second System.out.println(First) System.out.println System.out System System.out First
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		A = new int[N];
	}

	public boolean hasNext() {
		return cnt < N;
	}

	int[] A;
	int First = 1;
	int Second = 1;

	public void readBody(String str) {
		// System.out.println(str);
		int a = Integer.parseInt(str);
		A[cnt] = a;
		if (First < a)
			First = a;
		else if (Second < a)
			Second = a;
		cnt++;
	}

	public void solve() {
		for (int i = 0; i < N; i++) {
			if (A[i] == First)
				System.out.println(Second);
			else
				System.out.println(First);
		}
	}
}
