def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	A = [int(input()) for _ in range(N)]
	print(max(A[1:]))
	for i in range(1, N-1):
		print(max(max(A[:i]), max(A[i+1:])))
	print(max(A[:N]))

if __name__ == '__main__':
    main()