import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


N = int(input())
A = [int(input()) for _ in range(N)]

max_a = max(A)

for i in range(N):
    if A[i] == max_a:
        tmp = A[i]
        A[i] = NIL
        print(max(A))
        A[i] = tmp
        continue

    print(max_a)
