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

	print(max(A[:N-1]))

if __name__ == '__main__':
    main()