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

namespace AtCoder
{
    public static class Program
    {
        static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var forSort = new List<int>(N);
            var array = new int[N];
            foreach (var i in Enumerable.Range(0, N))
            {
                var v = int.Parse(Console.ReadLine());
                array[i] = v;
                forSort.Add(int.Parse(Console.ReadLine()));
            }
            forSort.Sort();

            var top = forSort[forSort.Count - 1];
            var second = forSort[forSort.Count - 2];

            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] == top)
                {
                    Console.WriteLine(second);
                    continue;
                }
                Console.WriteLine(top);
            }
        }
    }
}
