n = int(input())
lst = []
for _ in range(n):
  lst.append(int(input()))
set_ = list(set(lst))
set_.sort()
if len(set_)==1:
  print(set_[0])
else:
  max_ = set_[-1]
  next_max_ = set_[-2]
  for c in lst:
    if c==max_:
      print(next_max_)
    else:
      print(max_)