def main():
    n = int(input())
    a = list(int(input()) for _ in range(n))
    MAX1 = a[0]
    MAX2 = a[1]
    if MAX2 > MAX1:
        MAX1, MAX2 = MAX2, MAX1
    for j in a:
        if j >= MAX1:
            MAX1 = j
        elif j > MAX2:
            MAX2 = j
        else:
            continue
    for i in range(n):
        ans = MAX2 if a[i] == MAX1 else MAX1
        print(ans)


if __name__ == '__main__':
    main()