n = int(input())
_list = []

for _ in range(n):
    _list.append(int(input()))

for i in range(n):
    if i==0:
        tmp_list = _list[1:]
        tmp_max = max(tmp_list)
        print(tmp_max)
        
        if _list[0] < tmp_max:
            maxi = tmp_max
        else:
            maxi = _list[0]

    elif 0<i<n-1:
        if _list[i] < maxi:
            print(maxi)
        else:
            tmp_list = _list[:i] + _list[i+1:]
            print(max(tmp_list))

    else:
        if _list[i] < maxi:
            print(maxi)
        else:
            tmp_list = _list[:n-1]
            print(max(tmp_list))