import sys

#+++++
		
def main():
	n = int(input())
	ll=[int(input()) for _ in range(n)]
	
	mm = ll.sort()
	ma=mm[-1]
	mb=mm[-2]
	
	for i in ll:
		pp = ma if i != ma else mb:
		print(pp)
		
	
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)