#include <stdio.h>
#include <stdlib.h>

void swap(int *a, int*b)
{
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

void bsort(int *arr, int len)
{
	int i, j;

	for (i = 0; i < len; i++)
		for (j = len - 1; j > i; j--)
		{
			if (arr[i] > arr[j])
				swap(&arr[i], &arr[j]);
		}
}

int main()
{
	int n;
	int *arry = NULL;
	int i = 0;
	int j = 0;
	int max = 0;

	if (scanf("%d", &n) != 0)
		;
	arry = malloc(n * sizeof(int));
	for (; i < n; i++)
		if (scanf("%d", &arry[i]) != 0);

	bsort(arry, n);

	for (; j < n; j++)
	{
		if (j == (n-1))
			printf("%d\n", arry[n-2]);
		else
			printf("%d\n", arry[n-1]);
	}

	return 0;
}