using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication18
{
    class Program
    {
        static void nadi_zlatnik(int[,] mat, int n, out int x, out int y, out int maxi_v, out int maxi_k)
        {
            x = 0;
            y = 0;
            maxi_v = 0;
            maxi_k = 0;
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (i == 0)
                    {
                        if (mat[i, j] >= maxi_v)
                        {
                            maxi_v = mat[i, j];
                            x = j;
                        }
                    }
                    else
                    {
                        for (j = 0; j < n; j++)
                        {
                            if (mat[i, j] >= maxi_k)
                            {
                                maxi_v = mat[i, j];
                                y = j;
                            }
                        }
                    }
                }
            }
        }

        static void Main(string[] args)
        {
            bool[,] tabla;
            int dim;
            
            int n = int.Parse(Console.ReadLine());
            while (n <= 0)
            {
                
                n = int.Parse(Console.ReadLine());
            }
            tabla = new bool[n, n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    tabla[i, j] = false;
                }
            }
            string s;
            string[] s1;
            int x, y;
            for (int j = 0; j < n; j++)
            {
                do
                {
                    s = Console.ReadLine();
                    s1 = s.Split(' ');

                } while (s1.Length != 2);
                x = int.Parse(s1[0]);
                y = int.Parse(s1[1]);
                tabla[x - 1, y - 1] = true;
            }
            int vreme = 0;
            int[,] mat = new int[2, n];
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    mat[i, j] = 0;
                }
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (tabla[i, j] = true)
                    {
                        mat[0, i]++;
                        mat[1, j]++;
                    }
                }
            }
            x = 0;
            y = 0;

            int maxi_v = 0;
            int maxi_k = 0;
            nadi_zlatnik(mat, n, out x, out y, out maxi_v, out maxi_k);
        }
    }
}