using System;
using System.Collections.Generic;
using System.Linq;

namespace atcoder_code {
    class Program {
        static void Main (string[] args) {
            var input = Console.ReadLine ().Split (' ')
                .Select (x => int.Parse (x)).ToList ();
            var n = input[0];
            var list2 = new List<int> ();
            for (int i = 0; i < n; i++) {
                var a = Console.ReadLine ().Split (' ')
                    .Select (x => int.Parse (x)).ToList ();
                list2.Add (a[0]);
            }
            var list3 = list2;
            list2.Sort ();
            for (int i = 0; i < n; i++) {
                if (list3[i] == list2[n - 1]) {
                    Console.WriteLine (list2[n - 2]);
                } else {
                    Console.WriteLine (list2[n - 1]);
                }
            }
        }
    }
}