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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        token = lines[0].split()
        n = int(token[0])
        for i in range(n):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        token = lines[0].split()
        n = int(token[0])

    a = []
    for i in range(1, n+1):
        a.append(int(lines[i]))

    return (n, a)


def solve(n, a):

    for i in range(n):
        b = a[:i]
        if b:
          x = max(b)
        else:
          x = -1
        y = a[i]
        c = a[i+1:]
        if c:
          z = max(c)
        else:
          z = -1
        print(max(x, z))



def main():
    # 出力

    solve(*parse_input())

if __name__ == '__main__':

    main()
	