# -*- coding: utf-8 -*-

N = int(input()) 
s = [input() for i in range(N)] 

s_max = max(s)
for i in range(len(s)):
    temp = s.pop(i)
    if (temp == s_max):
        print(max(s))
    else:
        print(s_max)
    s.insert(i, temp)