N = int(input())
AList = [input() for i in range(N)]
max_AList = max(AList)
max2nd_AList = 0

for i in range(N) :
    if AList[i] == max_AList :
        if max2nd_AList == 0 :
            max2nd_AList = max(AList[0:i] + AList[i+1:N])
            print(max2nd_AList)
        else :
            print(max2nd_AList)
    else :
        print(max_AList)