def main():
	n = int(input())
	# n,m = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	l = [str(input()) for i in range(n)]
	#R行C列
	# a = [list(map(int,input().split())) for x in range(m)]
	# print(' '.join(map(str,)))

	# i = 0
	print(max(l[1:n]))
	m = max(l[1:n])

	# 0 < i < n
	for i in range(1,n):
		if l[i] == m:
			print(max( max(l[0:i]),max(l[i+1:n])))
		else:
			print(m)


if __name__ == '__main__':
	main()