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

namespace zadacha2
{
    class Program
    {
        static void Main()
        {
            byte n, m, k = 0, temp = 0, answer = 0;
            int max = -1;
            string[] Data = Console.ReadLine().Split(' ');
            n = Convert.ToByte(Data[0]);
            m = Convert.ToByte(Data[1]);
            int[,] election = new int[m, n];
            byte[] count = new byte[n + 1];

            for (byte i = 0; i < m; i++)
            {
                string[] Data1 = Console.ReadLine().Split(' ');
                for (byte j = 0; j < n; j++)
                {
                    election[i, j] = Convert.ToInt32(Data1[j]);
                    count[j + 1] = 0;
                }

            }

            for (byte i = 0; i < m; i++)
            {
                for (byte j = 0; j < n; j++)
                {
                    if (election[i, j] > max)
                    {
                        max = election[i, j];
                        temp = j;
                    }
                }
                count[temp + 1]++;
                max = 0;
            }

            for (byte i = 1; i <= n; i++)
            {
                if (count[i] > max)
                {
                    answer = i;
                    max = count[i];
                }
            }
            Console.WriteLine(answer);
        }
    }
}


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

namespace zadacha2
{
    class Program
    {
        static void Main()
        {
            byte n, m, k = 0, temp = 0, answer = 0;
            int max = -1;
            string[] Data = Console.ReadLine().Split(' ');
            n = Convert.ToByte(Data[0]);
            m = Convert.ToByte(Data[1]);
            int[,] election = new int[m, n];
            byte[] count = new byte[n + 1];

            for (byte i = 0; i < m; i++)
            {
                string[] Data1 = Console.ReadLine().Split(' ');
                for (byte j = 0; j < n; j++)
                {
                    election[i, j] = Convert.ToInt32(Data1[j]);
                    count[j + 1] = 0;
                }

            }

            for (byte i = 0; i < m; i++)
            {
                for (byte j = 0; j < n; j++)
                {
                    if (election[i, j] > max)
                    {
                        max = election[i, j];
                        temp = j;
                    }
                }
                count[temp + 1]++;
                max = -1;
            }

            for (byte i = 1; i <= n; i++)
            {
                if (count[i] > max)
                {
                    answer = i;
                    max = count[i];
                }
            }
            Console.WriteLine(answer);
        }
    }
}


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

namespace zadacha2
{
    class Program
    {
        static void Main()
        {
            byte n, m, k = 0, temp = 0, answer = 0;
            int max = 0;
            string[] Data = Console.ReadLine().Split(' ');
            n = Convert.ToByte(Data[0]);
            m = Convert.ToByte(Data[1]);
            int[,] election = new int[m, n];
            byte[] count = new byte[n + 1];

            for (byte i = 0; i < m; i++)
            {
                string[] Data1 = Console.ReadLine().Split(' ');
                for (byte j = 0; j < n; j++)
                {
                    election[i, j] = Convert.ToInt32(Data1[j]);
                    count[j + 1] = 0;
                }

            }

            for (byte i = 0; i < m; i++)
            {
                for (byte j = 0; j < n; j++)
                {
                    if (election[i, j] > max)
                    {
                        max = election[i, j];
                        temp = j;
                    }
                }
                count[temp + 1]++;
                max = 0;
            }

            for (byte i = 1; i <= n; i++)
            {
                if (count[i] > max)
                {
                    answer = i;
                    max = count[i];
                }
            }
            Console.WriteLine(answer);
        }
    }
}


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

namespace codeforce_570
{
    class Program
    {
        //div 2 round 316
        static void Main(string[] args)
        {
            string[] Input1 = Console.ReadLine().Split(' '); bool t = false;
            int n = Convert.ToInt32(Input1[0]), m = Convert.ToInt32(Input1[1]); string[] temp = new string[m]; int i =0, j =0,z =0; int count = 0; int[] count2 = new int[n];
            string[] input2 = new string[m];
            int[,] votes = new int[m, n];
            for ( i = 0; i < m; i++)
            {
                input2[i] = Console.ReadLine();
                temp = input2[i].Split(' ');
                for ( j = 0; j < temp.Length;j++ )
                    votes[i, j] = Convert.ToInt32(temp[j]);
            }
            if (n > 1)
            {
                for (i = 0; i < m; i++)
                {
                    count = votes[i, 0];
                    for (j = 1; j < n; j++)

                        count = Math.Max(votes[i, j], count);
                    for (z = 0; ; z++)
                        if (count == votes[i, z]) break;
                    count2[z]++;

                }
                if (t)
                {
                    for (i = 1; i < n; i++)
                        j = Math.Max(count2[i], count2[i - 1]);
                    for (i = 0; ; i++)
                        if (j == count2[i]) break;
                }
                Console.WriteLine(i + 1);
            }
            else Console.WriteLine(1);

        }
    }
}


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

namespace codeforce_570
{
    class Program
    {
        //div 2 round 316
        static void Main(string[] args)
        {
            string[] Input1 = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(Input1[0]), m = Convert.ToInt32(Input1[1]); string[] temp = new string[m]; int i =0, j =0,z =0; int count = 0; int[] count2 = new int[n];
            string[] input2 = new string[m];
            int[,] votes = new int[m, n];
            for ( i = 0; i < m; i++)
            {
                input2[i] = Console.ReadLine();
                temp = input2[i].Split(' ');
                for ( j = 0; j < temp.Length;j++ )
                    votes[i, j] = Convert.ToInt32(temp[j]);
            }
            for (i = 0; i < m; i++)
            {
                count = votes[i, 0];
                for (j = 1; j < n; j++)
                    count = Math.Max(votes[i, j], count);
                for ( z = 0; ; z++)
                    if (count == votes[i,z]) break;
                count2[z]++;
            }
            for (i = 1; i < n; i++)
                j = Math.Max(count2[i], count2[i - 1]);
            for (i = 0; ; i++)
                if (j == count2[i]) break;
            Console.WriteLine(i+1);

        }
    }
}


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

namespace codeforce_570
{
    class Program
    {
        //div 2 round 316
        static void Main(string[] args)
        {
            string[] Input1 = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(Input1[0]), m = Convert.ToInt32(Input1[1]);
            string[] temp = new string[m]; int i =0, j =0,z =0; int count = 0; int[] count2 = new int[n];
                string[] input2 = new string[m];
                int[,] votes = new int[m, n];
                for (i = 0; i < m; i++)
                {
                    input2[i] = Console.ReadLine();
                    temp = input2[i].Split(' ');
                    for (j = 0; j < temp.Length; j++)
                        votes[i, j] = Convert.ToInt32(temp[j]);
                }
                for (i = 0; i < m; i++)
                {
                    count = votes[i, 0];
                    for (j = 0; j < n; j++)
                        count = Math.Max(votes[i, j], count);
                    for (z = 0; ; z++)
                        if (count == votes[i, z]) break;
                    count2[z]++;
                }
                j = 0;
                for (i = 0; i < n; i++)
                    j = Math.Max(count2[i],j);
                for (i = 0; ; i++)
                    if (j == count2[i]) break;
                Console.WriteLine(i + 1);
        }
    }
}


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

namespace codeforce_570
{
    class Program
    {
        //div 2 round 316
        static void Main(string[] args)
        {
            string[] Input1 = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(Input1[0]), m = Convert.ToInt32(Input1[1]); string[] temp = new string[m]; int i =0, j =0,z =0; int count = 0; int[] count2 = new int[n];
            if (n > 1)
            {
                string[] input2 = new string[m];
                int[,] votes = new int[m, n];
                for (i = 0; i < m; i++)
                {
                    input2[i] = Console.ReadLine();
                    temp = input2[i].Split(' ');
                    for (j = 0; j < temp.Length; j++)
                        votes[i, j] = Convert.ToInt32(temp[j]);
                }
                for (i = 0; i < m; i++)
                {
                    count = votes[i, 0];
                    for (j = 1; j < n; j++)
                        count = Math.Max(votes[i, j], count);
                    for (z = 0; ; z++)
                        if (count == votes[i, z]) break;
                    count2[z]++;
                }
                for (i = 1; i < n; i++)
                    j = Math.Max(count2[i], count2[i - 1]);
                for (i = 0; ; i++)
                    if (j == count2[i]) break;
                Console.WriteLine(i + 1);
            }
            else Console.WriteLine(1);

        }
    }
}


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

namespace deneme
{
    class Program
    {
       static void Main(string[] args)
       {
            try
            {
                var x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                int[] oylar = new int[x[0]];
                for (int i = 0; i < x[1]; i++)
                {
                    var s = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    oylar[Array.IndexOf(s, s.Max())] ++;
                }
                Console.Write(Array.IndexOf(oylar,oylar.Max())+1);
                Console.ReadKey();
            }
            catch { }
        }
    }
}


using System;
namespace _570a
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {

                int sayac = 0;
                int[] nm = new int[2];
                string nnm = Console.ReadLine();
                foreach (string str in nnm.Split(' '))
                {
                    nm[sayac] = int.Parse(str);
                    sayac++;
                }
                string[] oylar = new string[nm[1]];
                for (int i = 0; i < nm[1]; i++)
                {
                    oylar[i] = Console.ReadLine();
                }
                Console.ReadKey();
            }
            catch
            {  }
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace StudyCSharp
{
    class Program
    {
        private static int[,] array;
        private static int n;
        private static int m;

        static void Main(string[] args)
        {
            string[] NM = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(NM[0]);
            int m = Convert.ToInt32(NM[1]);

            string[] ForInput = new string[m];
            array = new int[m, n];

            for (int i = 0; i < m; i++)
            {
                ForInput = Console.ReadLine().Split(' ');
                for (int j = 0; j < n; j++)
                    array[i, j] = Convert.ToInt32(ForInput[j]);
            }

            int[] c = new int[n];
            for (int i = 0; i < m; i++)
                c[FindMax(i)]++;

            int answer = FindMax(c);
            Console.WriteLine(answer);
        }

        private static int FindMax(int i)
        {
            int max = array[i, 0];
            int index = 0;
            for (int j = 0; j < n; j++)
            {
                if (array[i, j] > max)
                {
                    max = array[i, j];
                    index = j;
                }
            }

            return index;
        }

        private static int FindMax(int[] a)
        {
            int max = a[0];
            int index = 1;
            for (int i = 0; i < n; i++)
            {
                if (a[i] > max)
                {
                    max = a[i];
                    index = i + 1;
                }
            }

            return index;
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace StudyCSharp
{
    class Program
    {
        private static int[,] array;
        private static int n;
        private static int m;

        static void Main(string[] args)
        {
            string[] NM = Console.ReadLine().Split(' ');
            n = Convert.ToInt32(NM[0]);
            m = Convert.ToInt32(NM[1]);

            string[] ForInput = new string[m];
            array = new int[m, n];

            for (int i = 0; i < m; i++)
            {
                ForInput = Console.ReadLine().Split(' ');
                for (int j = 0; j < n; j++)
                    array[i, j] = Convert.ToInt32(ForInput[j]);
            }

            //======================================================

            int[] c = new int[n];
            for (int i = 0; i < m; i++)
                c[FindMax(i)]++;

            int answer = FindMax(c);
            Console.WriteLine(answer);
        }

        private static int FindMax(int i)
        {
            int max = array[i, 0];
            int index = 0;
            for (int j = 0; j < n; j++)
            {
                if (array[i, j] > max)
                {
                    max = array[i, j];
                    index = j;
                }
            }

            return index;
        }

        private static int FindMax(int[] a)
        {
            int max = a[0];
            int index = 1;
            for (int i = 0; i < n; i++)
            {
                if (a[i] > max)
                {
                    max = a[i];
                    index = i + 1;
                }
            }

            return index;
        }
    }
}


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

namespace Elections {
  class Program {

    static void Main(string[] args) {

      var gpData = Console.ReadLine().Split(' ');
      Int64 persons = Convert.ToInt64(gpData[0]);
      Int64 cities = Convert.ToInt64(gpData[1]);
      Int64 max = 0;
      Int64 indexVal = 0;
      Int64[,] allVotes = new Int64[cities,persons];
      Int64 count = 0;

      for(int i = 0; i < cities; i++) {
        Int64[] values = Array.ConvertAll(Console.ReadLine().Split(' '), s => Int64.Parse(s));
        for(int j = 0; j < persons; j++) {
          allVotes[i, j] = values[j];
        }
      }

      for(int i = 0; i < cities; i++) {
        count = 0;
        Int64 val = 0;
        while(count < persons) {
          val += allVotes[i,count];
          count++;
        }
        if(val >= max && i <= indexVal) {
          max = val;
          indexVal = i;
        }
      }
      Console.WriteLine("{0}", indexVal + 1);
    }
  }
}


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

namespace Elections {
  class Program {

    static void Main(string[] args) {

      var gpData = Console.ReadLine().Split(' ');
      Int64 persons = Convert.ToInt64(gpData[0]);
      Int64 cities = Convert.ToInt64(gpData[1]);
      Int64 max = 0;
      Int64 indexVal = 0;
      Int64 count = 0;
      Dictionary<Int64,int> data = new Dictionary<Int64,int>();

      for(int i = 0; i < cities; i++) {
        Int64[] values = Array.ConvertAll(Console.ReadLine().Split(' '), s => Int64.Parse(s));
        max = 0;
        indexVal = 0;
        for(int j = 0; j < persons; j++) {
          if(values[j] > max) {
            max = values[j];
            indexVal = j;
          }
        }
        if(data.ContainsKey(indexVal + 1)) {
          data[indexVal + 1]++;
        } else {
          data.Add(indexVal + 1, 1);
        }
      }

      max = 0;
      indexVal = 1;
      foreach(var item in data) {
        if(item.Value == max && item.Key <= indexVal || item.Value > max) {
          max = item.Value;
          indexVal = item.Key;
        }
      }
      Console.WriteLine("{0}", indexVal);
    }
  }
}


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

namespace Elections {
  class Program {

    static void Main(string[] args) {

      var gpData = Console.ReadLine().Split(' ');
      Int64 persons = Convert.ToInt64(gpData[0]);
      Int64 cities = Convert.ToInt64(gpData[1]);
      Int64 max = 0;
      Int64 indexVal = 0;
      Int64[,] allVotes = new Int64[cities,persons];
      Int64 count = 0;

      for(int i = 0; i < cities; i++) {
        Int64[] values = Array.ConvertAll(Console.ReadLine().Split(' '), s => Int64.Parse(s));
        for(int j = 0; j < persons; j++) {
          allVotes[i, j] = values[j];
        }
      }

      for(int i = 0; i < persons; i++) {
        count = 0;
        Int64 val = 0;
        while(count < cities) {
          val += allVotes[count, i];
          count++;
        }
        if(val == max && i <= indexVal || val > max) {
          max = val;
          indexVal = i;
        }
      }
      Console.WriteLine("{0}", indexVal + 1);

    }
  }
}


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

namespace Elections {
  class Program {

    static void Main(string[] args) {

      var gpData = Console.ReadLine().Split(' ');
      Int64 persons = Convert.ToInt64(gpData[0]);
      Int64 cities = Convert.ToInt64(gpData[1]);
      Int64 max = 0;
      Int64 indexVal = 0;
      Int64 count = 0;
      Dictionary<Int64,int> data = new Dictionary<Int64,int>();

      for(int i = 0; i < cities; i++) {
        Int64[] values = Array.ConvertAll(Console.ReadLine().Split(' '), s => Int64.Parse(s));
        max = 0;
        for(int j = 0; j < persons; j++) {
          if(values[j] > max) {
            max = values[j];
            indexVal = j;
          }
        }
        if(data.ContainsKey(indexVal + 1)) {
          data[indexVal + 1]++;
        } else {
          data.Add(indexVal + 1, 1);
        }
      }

      max = 0;
      indexVal = 1;
      foreach(var item in data) {
        if(item.Value == max && item.Key <= indexVal || item.Value > max) {
          max = item.Value;
          indexVal = item.Key;
        }
      }
      Console.WriteLine("{0}", indexVal);
    }
  }
}


using System;
using System.Linq;

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {

            int n = 0;
            int m = 0;

            string nM = Console.ReadLine();// количество кандидатов

            var splitRes = nM.Split(' ');

            n = Convert.ToInt32(splitRes[0]);
            m = Convert.ToInt32(splitRes[1]);
            int[] numberOfCit = new int[n];

            for (var i = 0; i < m; i++)
            {
                string s1 = Console.ReadLine();
                int[] ia = s1.Split(' ').Select(num => Convert.ToInt32(num)).ToArray();
                numberOfCit[IndexOfMax(ia)]++;
            }

            Console.Write(IndexOfMax(numberOfCit)+1);
        }

        static int IndexOfMax(int[] array)
        {
            int max = array[0];
            int index = 0;
            for (int i = 1; i < array.Length; i++)
            {
                if (array[i] > max)
                {
                    max = array[i];
                    index = i;
                }
            }

            return index;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class CF316_1
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader(@"D:\Sergey\Code\CodeForces\316\1.txt"));

            string strT = Console.ReadLine();
            string[] strParams = strT.Split(new char[] { ' ' });
            int n = int.Parse(strParams[0]);
            int m = int.Parse(strParams[1]);

            int[] k = new int[m];
            for (int j = 0; j < m; j++)
                k[j] = 0;

            int b = 0, index = 0;
            int[,] a = new int[m, n];
            for (int i = 0; i < m; i++)
            {
                strT = Console.ReadLine();
                strParams = strT.Split(new char[] { ' ' });

                int[] km = new int[n];
                //var km = new List<int>(n);
                int max = 0, ind = 0;
                for (int j = 0; j < n; j++)
                    km[j] = 0;
                for (int j = 0; j < n; j++)
                {
                    a[i,j] = int.Parse(strParams[j]) - 1 ;
                    //km[a[i, j]]++;
                    if (max < a[i, j])
                    {
                        max = a[i, j];
                        ind = j;
                    }
                    else if (max == a[i, j])
                    {
                        if (j < ind)
                            ind = j;
                    }
                }

                k[ind]++;
                if (b < k[ind])
                {
                    b = k[ind];
                    index = ind;
                }
                else if (b == k[ind])
                {
                    if (ind < index)
                        index = ind;
                }
            }

            Console.WriteLine((index + 1).ToString());
        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class CF316_1
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader(@"D:\Sergey\Code\CodeForces\316\1.txt"));

            string strT = Console.ReadLine();
            string[] strParams = strT.Split(new char[] { ' ' });
            int n = int.Parse(strParams[0]);
            int m = int.Parse(strParams[1]);

            int[] k = new int[m];
            for (int j = 0; j < m; j++)
                k[j] = 0;

            int b = 0, index = 0;
            int[,] a = new int[m, n];
            for (int i = 0; i < m; i++)
            {
                strT = Console.ReadLine();
                strParams = strT.Split(new char[] { ' ' });

                int[] km = new int[n];
                //var km = new List<int>(n);
                int max = int.MinValue, ind = 0;
                for (int j = 0; j < n; j++)
                    km[j] = 0;
                for (int j = 0; j < n; j++)
                {
                    a[i,j] = int.Parse(strParams[j]) - 1 ;
                    //km[a[i, j]]++;
                    if (max < a[i, j])
                    {
                        max = a[i, j];
                        ind = j;
                    }
                    else if (max == a[i, j])
                    {
                        if (j < ind)
                            ind = j;
                    }
                }

                k[ind]++;
                if (b < k[ind])
                {
                    b = k[ind];
                    index = ind;
                }
                else if (b == k[ind])
                {
                    if (ind < index)
                        index = ind;
                }
            }

            Console.WriteLine((index + 1).ToString());
        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class CF316_1
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader(@"D:\Sergey\Code\CodeForces\316\1.txt"));

            string strT = Console.ReadLine();
            string[] strParams = strT.Split(new char[] { ' ' });
            int n = int.Parse(strParams[0]);
            int m = int.Parse(strParams[1]);

            int[] k = new int[n];
            for (int j = 0; j < n; j++)
                k[j] = 0;

            int b = 0, index = 0;
            int[,] a = new int[m, n];
            for (int i = 0; i < m; i++)
            {
                strT = Console.ReadLine();
                strParams = strT.Split(new char[] { ' ' });

                int[] km = new int[n];
                //var km = new List<int>(n);
                int max = int.MinValue, ind = 0;
                for (int j = 0; j < n; j++)
                    km[j] = 0;
                for (int j = 0; j < n; j++)
                {
                    a[i,j] = int.Parse(strParams[j]) - 1 ;
                    //km[a[i, j]]++;
                    if (max < a[i, j])
                    {
                        max = a[i, j];
                        ind = j;
                    }
                    else if (max == a[i, j])
                    {
                        if (j < ind)
                            ind = j;
                    }
                }

                k[ind]++;
                if (b < k[ind])
                {
                    b = k[ind];
                    index = ind;
                }
                else if (b == k[ind])
                {
                    if (ind < index)
                        index = ind;
                }
            }

            Console.WriteLine((index + 1).ToString());
        }

    }
}


using System;
using System.Collections.Generic;
using System.IO;

namespace prA {
    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter(@"..\..\output");
        private static readonly StreamReader reader = new StreamReader(@"..\..\input");
#endif

        static void Main(string[] args) {
            int n = Next();
            int m = Next();
            int[] c = new int[n + 1];
            int winner = -1;
            for (int i = 0; i < m; i++) {
                int cityMax = Next();
                int maxI = 1;
                for (int j = 1; j < n; j++) {
                    int cc = Next();
                    if (cc > cityMax) {
                        cityMax = cc;
                        maxI = j + 1;
                    }
                }
                c[maxI]++;
                if (winner == -1 || c[winner] < c[maxI] || (c[winner]==c[maxI] && maxI < winner)) {
                    winner = maxI;
                }
            }
            writer.Write(winner);

            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int Next() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;

namespace prA {
    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter(@"..\..\output");
        private static readonly StreamReader reader = new StreamReader(@"..\..\input");
#endif

        static void Main(string[] args) {
            int n = Next();
            int m = Next();
            int[] c = new int[n + 1];
            int winner = -1;
            for (int i = 0; i < m; i++) {
                int cityMax = Next();
                int maxI = 1;
                for (int j = 1; j < n; j++) {
                    int cc = Next();
                    if (cc > cityMax) {
                        cityMax = cc;
                        maxI = j + 1;
                    }
                }
                c[maxI]++;
                if (winner == -1 || c[winner] < c[maxI]) {
                    winner = maxI;
                }
            }
            writer.Write(winner);

            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int Next() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


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

namespace Contest570
{
    public class A_Elections
    {
        public static void Main()
        {
            var firstLine = Console.ReadLine();
            var n_m = firstLine.Split(' ');

            var candidates = int.Parse(n_m[0]);
            var cities = int.Parse(n_m[1]);

            var solution = Solve(candidates, cities, Console.In);
            Console.WriteLine(solution);
        }

        public static int Solve(int candidates, int cities, TextReader reader)
        {
            var candidateWinCounts = new int[candidates];

            for (int city = 0; city < cities; city++)
            {
                var line = reader.ReadLine();
                var candidatesPerCity = line.Split(' ');

                var maxCandidate = -1;
                var maxValue = -1;

                for (int candidate = 0; candidate < candidates; candidate++)
                {
                    int value = int.Parse(candidatesPerCity[candidate]);
                    if (value > maxValue)
                    {
                        maxValue = value;
                        maxCandidate = candidate;
                    }
                }

                candidateWinCounts[maxCandidate]++;
            }

            var maxCandidateStage2 = -1;
            var maxValueStage2 = -1;
            for (int candidate = 0; candidate < candidates; candidate++)
            {
                var value = candidateWinCounts[candidate];
                if (value > maxValueStage2)
                {
                    maxValueStage2 = value;
                    maxCandidateStage2 = candidate;
                }
            }

            return maxCandidateStage2 + 1;
        }
    }
}


using System;
using System.Linq;

public class Program
{
	public static void Main()
	{
		int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int n = nm[0], m = nm[1];
		int[] candidates = new int[n];
		for (int i = 0; i < m; i++)
		{
			int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int chosen = a.Select((v, idx) => new { Vote = v, Index = idx })
				.OrderByDescending(item => item.Vote).ThenBy(item => item.Index)
				.Select(item => item.Index).First();
			candidates[chosen]++;
		}
		int ans = candidates.Select((w, idx) => new { Win = w, Index = idx })
				.OrderByDescending(item => item.Win).ThenBy(item => item.Index)
				.Select(item => item.Index + 1).First();
		Console.WriteLine(ans);
	}
}


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

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
            int[] candidates = new int[x[0]];

            for (int i = 0; i < x[1]; i++)
            {
                int[] l = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
                int m = l.Max();
                for (int j = 0; j < l.Length; j++)
                {
                    if (l[j] == m)
                    {
                        candidates[j] += 1;
                        break;
                    }
                }
            }
            int mx = candidates.Max();
            for (int j = 0; j < candidates.Length; j++)
            {
                if (candidates[j] == mx)
                {
                    Console.WriteLine(++j);
                    break;
                }
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
//using System.Numerics;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var a = ReadIntMatrix(m);
        var cnt = new int[n];
        for (int i = 0; i < m; i++)
        {
            int best = 0;
            for (int j = 1; j < n; j++)
            {
                if (a[i][j] > a[i][best])
                    best = j;
            }
            cnt[best]++;
        }

        int ans = 0;
        for (int i = 1; i < n; i++)
            if (cnt[i] > cnt[ans])
                ans = i;

        Write(ans + 1);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("hull.in");
        //writer = new StreamWriter("hull.out");
#endif
        try
        {
            //            var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //            thread.Start();
            //            thread.Join();
            checked
            {
                new Solver().Solve();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
//using System.Numerics;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var a = ReadIntMatrix(m);
        var pob1 = new int[m];
        int pob2 = 0;
        int count = 0;
        int max;
        for (int i = 0; i < m; i++)
        {
            max = 0;
            for (int j = 0; j < n; j++)
            {
                if (a[i][j] > max)
                {
                    max = a[i][j];
                    pob1[i] = j;
                }
            }
        }

        max = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (i == pob1[j])
                    count++;
            }

            if (count > max)
            {
                max = count;
                pob2 = i;
            }
            count = 0;
        }

        Write(pob2 + 1);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("hull.in");
        //writer = new StreamWriter("hull.out");
#endif
        try
        {
            //            var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //            thread.Start();
            //            thread.Join();
            checked
            {
                new Solver().Solve();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var a = ReadIntMatrix(m);

        var cnt = new int[n];
        for (int i = 0; i < m; i++)
        {
            int nmax = 0;
            for (int j = 1; j < n; j++)
                if (a[i][j] > a[i][nmax])
                    nmax = j;
            cnt[nmax]++;
        }

        int nmx = 0;
        for (int i = 1; i < n; i++)
            if (cnt[i] > cnt[nmx])
                nmx = i;

        Write(nmx + 1);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("hull.in");
        //writer = new StreamWriter("hull.out");
#endif
        try
        {
            //            var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //            thread.Start();
            //            thread.Join();
            checked
            {
                new Solver().Solve();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


using System;
using System.Linq;

namespace tren
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] vs = new int[nm[0]];
            for(int i = 0; i < nm[1]; i++)
            {
                int[] city = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int max = Array.IndexOf(city, city.Max());
                vs[max]++;
            }
            Console.Write(Array.IndexOf(vs, vs.Max()) + 1);
        }
    }
}


using System;
using System.Linq;

namespace tren
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] vs = new int[nm[1]];
            for(int i = 0; i < nm[1]; i++)
            {
                int[] city = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int max = Array.IndexOf(city, city.Max());
                vs[max]++;
            }
            Console.Write(Array.IndexOf(vs, vs.Max()) + 1);
        }
    }
}


using System;
using System.Text;
using System.Collections.Generic;

namespace cfcs
{
    class Program
    {

        bool gu(ref int v)
        {
            int u, c;
            for (c = Console.In.Read(); c != -1; c = Console.In.Read())
            {
                if (char.IsDigit((char)c))
                {
                    u = c - '0';
                    for (c = Console.In.Read(); c != -1; c = Console.In.Read())
                    {
                        if (char.IsDigit((char)c))
                        {
                            u = 10 * u + c - '0';
                            continue;
                        }

                        break;
                    }

                    v = u;
                    return true;
                }
            }

            return false;
        }

        int gu()
        {
            int u, c;
            for (c = Console.In.Read(); c != -1; c = Console.In.Read())
            {
                if (char.IsDigit((char)c))
                {
                    u = c - '0';
                    for (c = Console.In.Read(); c != -1; c = Console.In.Read())
                    {
                        if (char.IsDigit((char)c))
                        {
                            u = 10 * u + c - '0';
                            continue;
                        }

                        break;
                    }

                    return u;
                }
            }

            return 0;
        }

        private void solve()
        {
            int n, m, w, ans = 1;
            int[] a;
            n = gu();
            m = gu();
            a = new int[n + 1];

            for (int i = 0; i < m; ++i)
            {
                w = -1;
                for (int j = 1; j <= n; ++j)
                {
                    int g = gu();
                    if (g > w)
                    {
                        w = g;
                        ans = j;
                    }
                }

                ++a[ans];
            }

            w = -1;
            for (int j = 1; j <= n; ++j)
            {
                if (a[j] > w)
                {
                    w = a[j];
                    ans = j;
                }
            }

            Console.WriteLine(ans);
        }

        static void Main()
        {
            Program app = new Program();
            app.solve();
        }
    }
}


using System;
using System.Text;
using System.Collections.Generic;

namespace cfcs
{
    class Program
    {

        bool gu(ref int v)
        {
            int u, c;
            for (c = Console.In.Read(); c != -1; c = Console.In.Read())
            {
                if (char.IsDigit((char)c))
                {
                    u = c - '0';
                    for (c = Console.In.Read(); c != -1; c = Console.In.Read())
                    {
                        if (char.IsDigit((char)c))
                        {
                            u = 10 * u + c - '0';
                            continue;
                        }

                        break;
                    }

                    v = u;
                    return true;
                }
            }

            return false;
        }

        int gu()
        {
            int u, c;
            for (c = Console.In.Read(); c != -1; c = Console.In.Read())
            {
                if (char.IsDigit((char)c))
                {
                    u = c - '0';
                    for (c = Console.In.Read(); c != -1; c = Console.In.Read())
                    {
                        if (char.IsDigit((char)c))
                        {
                            u = 10 * u + c - '0';
                            continue;
                        }

                        break;
                    }

                    return u;
                }
            }

            return 0;
        }

        private void solve()
        {
            int n, m, w, ans = 1;
            int[] a;
            n = gu();
            m = gu();
            a = new int[n + 1];

            for (int i = 0; i < m; ++i)
            {
                for (int j = 1; j <= n; ++j)
                {
                    a[j] += gu();
                }
            }

            w = a[1];
            for (int j = 1; j <= n; ++j)
            {
                if (a[j] > w)
                {
                    w = a[j];
                    ans = j;
                }
            }

            Console.WriteLine(ans);
        }

        static void Main()
        {
            Program app = new Program();
            app.solve();
        }
    }
}


using System;
using System.Text;
using System.Collections.Generic;

namespace cfcs
{
    class Program
    {

        bool gu(ref int v)
        {
            int u, c;
            for (c = Console.In.Read(); c != -1; c = Console.In.Read())
            {
                if (char.IsDigit((char)c))
                {
                    u = c - '0';
                    for (c = Console.In.Read(); c != -1; c = Console.In.Read())
                    {
                        if (char.IsDigit((char)c))
                        {
                            u = 10 * u + c - '0';
                            continue;
                        }

                        break;
                    }

                    v = u;
                    return true;
                }
            }

            return false;
        }

        int gu()
        {
            int u, c;
            for (c = Console.In.Read(); c != -1; c = Console.In.Read())
            {
                if (char.IsDigit((char)c))
                {
                    u = c - '0';
                    for (c = Console.In.Read(); c != -1; c = Console.In.Read())
                    {
                        if (char.IsDigit((char)c))
                        {
                            u = 10 * u + c - '0';
                            continue;
                        }

                        break;
                    }

                    return u;
                }
            }

            return 0;
        }

        private void solve()
        {
            int n, m, w, ans = 1;
            int[] a;
            n = gu();
            m = gu();
            a = new int[n + 1];

            for (int i = 0; i < m; ++i)
            {
                w = 0;
                for (int j = 1; j <= n; ++j)
                {
                    int g = gu();
                    if (g > w)
                    {
                        w = g;
                        ans = j;
                    }
                }

                ++a[ans];
            }

            w = 0;
            for (int j = 1; j <= n; ++j)
            {
                if (a[j] > w)
                {
                    w = a[j];
                    ans = j;
                }
            }

            Console.WriteLine(ans);
        }

        static void Main()
        {
            Program app = new Program();
            app.solve();
        }
    }
}


using System;
using System.Linq;

class Program
{
    private static void Main()
    {
        int result = 0;
        var nm = ConsoleReadLineAsArrayOfIntegers();
        int n = nm[0];  int m = nm[1];
        int[] cand = new int[n];
        for(int j = 0; j < n; j++)
            cand[j] = 0;

        for(int i = 0; i < m; i++)
        {
            var r = ConsoleReadLineAsArrayOfIntegers();
            int max = 0;
            for(int j = 0; j < n; j++)
                if (r[j] > r[max]) max = j;

            cand[max]++;
        }

        //for(int i = 0; i < n; i++)
        //  Console.Write(" " + cand[i]);

        for(int i = 0; i < n; i++)
            if (cand[i] > cand[result]) result = i;

        result++;

        Console.WriteLine("" + result);
    }

    private static int[] ConsoleReadLineAsArrayOfIntegers()
    {
        return Console.ReadLine().Split(' ').Select(n => Convert.ToInt32(n)).ToArray();
    }

    private static int ConsoleReadLineAsInteger()
    {
        return Convert.ToInt32(Console.ReadLine());
    }

    private static void ConsoleWriteLine(string line)
    {
        Console.WriteLine(line);
    }
}


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

namespace _570A
{
    class Program
    {
        static int MaxIndex(string[] data)
        {
            var indexMax = -1;
            var max = Convert.ToInt32(data[0]);
            for (int i = 1; i < data.Length; i++)
            {
                var currentValue = Convert.ToInt32(data[i]);
                if (max < currentValue)
                {
                    max = currentValue;
                    indexMax = i;
                }
            }
            return indexMax;
        }
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var n = Convert.ToInt32(input[0]);
            var m = Convert.ToInt32(input[1]);
            var candidates = new SortedDictionary<int, int>();
            for (int i = 0; i < n; i++)
            {
                candidates[i] = 0;
            }
            for (int i = 0; i < m; i++)
            {
                var voices = Console.ReadLine().Split(' ');
                candidates[MaxIndex(voices)]++;
            }
            var max = candidates.Values.Max();
            var result = -1;
            foreach (var key in candidates.Keys)
            {
                if (candidates[key] == max)
                {
                    result = key + 1;
                    break;
                }
            }
            Console.WriteLine(result);
        }
    }
}


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

namespace _570A
{
    class Program
    {
        static int MaxIndex(string[] data)
        {
            var indexMax = 0;
            var max = Convert.ToInt32(data[0]);
            for (int i = 1; i < data.Length; i++)
            {
                var currentValue = Convert.ToInt32(data[i]);
                if (max < currentValue)
                {
                    max = currentValue;
                    indexMax = i;
                }
            }
            return indexMax;
        }
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var n = Convert.ToInt32(input[0]);
            var m = Convert.ToInt32(input[1]);
            var candidates = new SortedDictionary<int, int>();
            for (int i = 0; i < n; i++)
            {
                candidates[i] = 0;
            }
            for (int i = 0; i < m; i++)
            {
                var voices = Console.ReadLine().Split(' ');
                candidates[MaxIndex(voices)]++;
            }
            var max = candidates.Values.Max();
            var result = -1;
            foreach (var key in candidates.Keys)
            {
                if (candidates[key] == max)
                {
                    result = key + 1;
                    break;
                }
            }
            Console.WriteLine(result);
        }
    }
}


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

namespace contest
{
    class Program
    {
        static void Main(string[] args)
        {
            var n_m = new List<int>(Array.ConvertAll<string, int>(Console.ReadLine().Split(), int.Parse));
            int N = n_m[1];
            Dictionary<int, int> candidates = new Dictionary<int, int>();
            for (int i = 1; i <= n_m[0]; i++)
                candidates.Add(i, 0);
            for (int i = 0; i < N; i++)
            {
                var nt = new List<int>(Array.ConvertAll<string, int>(Console.ReadLine().Split(), int.Parse));
                int max = -1, mInd = -1;
                for (int j = 0; j < nt.Count; j++)
                    if (max < nt[j]) { max = nt[j]; mInd = j + 1; }
                candidates[mInd]++;
            }
            int maxValue = candidates.Values.Max();
            foreach (var kv in candidates)
                if (kv.Value == maxValue)
                {
                    Console.WriteLine(kv.Key);
                    break;
                }
        }
    }
}


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

namespace contest
{
    class Program
    {
        static void Main(string[] args)
        {
            var n_m = new List<int>(Array.ConvertAll<string, int>(Console.ReadLine().Split(), int.Parse));
            int N = n_m[1];
            Dictionary<int, int> candidates = new Dictionary<int, int>();
            for (int i = 1; i <= n_m[0]; i++)
                candidates.Add(i, 0);
            for (int i = 0; i < N; i++)
            {
                var nt = new List<int>(Array.ConvertAll<string, int>(Console.ReadLine().Split(), int.Parse));
                int max = 0, mInd = -1;
                for (int j = 0; j < nt.Count; j++)
                    if (max < nt[j]) { max = nt[j]; mInd = j + 1; }
                candidates[mInd]++;
            }
            int maxValue = candidates.Values.Max();
            foreach (var kv in candidates)
                if (kv.Value == maxValue)
                {
                    Console.WriteLine(kv.Key);
                    break;
                }
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string x,c;
            x = Console.ReadLine();
            int a = Convert.ToInt32(x.Split(' ')[0]);
            int b = Convert.ToInt32(x.Split(' ')[1]);
            int[] w = new int[a+1];
            int[] e = new int[4];
            int y, u, max;

            for (int i = 0; i < b; i++)
            {
                 c = Console.ReadLine();
                e[0] = -1;
                for (int j = 0; j < a; j++)
                {
                    if (e[0] < int.Parse(c.Split(' ')[j]))
                    {
                        e[0] = int.Parse(c.Split(' ')[j]);
                        e[1] = j + 1;
                    }
                }
                w[e[1]]++;
                e[1] = 1;
            }
            for (int k = 0; k < a+1; k++)
            {
                if (e[2] < w[k])
                {
                    e[2]= w[k];
                    e[3] = k;
                }
            }
            Console.WriteLine(e[3]);
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string x,c;
            x = Console.ReadLine();
            int a = Convert.ToInt32(x.Split(' ')[0]);
            int b = Convert.ToInt32(x.Split(' ')[1]);
            int[] w = new int[a+1];
            int[] e = new int[4];
            int y, u, max;

            for (int i = 0; i < b; i++)
            {
                 c = Console.ReadLine();
                for (int j = 0; j < a; j++)
                {
                    if (e[0] < int.Parse(c.Split(' ')[j]))
                    {
                        e[0] = int.Parse(c.Split(' ')[j]);
                        e[1] = j + 1;
                    }
                }
                w[e[1]]++;
                e[0] = 0;
            }
            for (int k = 0; k < a; k++)
            {
                if (e[2] < w[k])
                {
                    e[2]= w[k];
                    e[3] = k;
                }
            }
            Console.WriteLine(e[3]);
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string x,c;
            x = Console.ReadLine();
            int a = Convert.ToInt32(x.Split(' ')[0]);
            int b = Convert.ToInt32(x.Split(' ')[1]);
            int[] w = new int[a+1];
            int[] e = new int[4];
            int y, u, max;

            for (int i = 0; i < b; i++)
            {
                 c = Console.ReadLine();
                for (int j = 0; j < a; j++)
                {
                    if (e[0] < int.Parse(c.Split(' ')[j]))
                    {
                        e[0] = int.Parse(c.Split(' ')[j]);
                        e[1] = j + 1;
                    }
                }
                w[e[1]]++;
                e[0] = -1;
                e[1] = 0;
            }
            for (int k = 0; k < a+1; k++)
            {
                if (e[2] < w[k])
                {
                    e[2]= w[k];
                    e[3] = k;
                }
            }
            if ((a==1)&&(b==1)) { Console.WriteLine("1"); } else
            Console.WriteLine(e[3]);
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string x,c;
            x = Console.ReadLine();
            int a = Convert.ToInt32(x.Split(' ')[0]);
            int b = Convert.ToInt32(x.Split(' ')[1]);
            int[] w = new int[a+1];
            int[] e = new int[4];
            int y, u, max;

            for (int i = 0; i < b; i++)
            {
                 c = Console.ReadLine();
                for (int j = 0; j < a; j++)
                {
                    if (e[0] < int.Parse(c.Split(' ')[j]))
                    {
                        e[0] = int.Parse(c.Split(' ')[j]);
                        e[1] = j + 1;
                    }
                }
                w[e[1]]++;
                e[0] = 0;
                e[1] = 0;
            }
            for (int k = 0; k < a+1; k++)
            {
                if (e[2] < w[k])
                {
                    e[2]= w[k];
                    e[3] = k;
                }
            }
            Console.WriteLine(e[3]);
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string x,c;
            x = Console.ReadLine();
            int a = Convert.ToInt32(x.Split(' ')[0]);
            int b = Convert.ToInt32(x.Split(' ')[1]);
            int[] w = new int[a+1];
            int[] e = new int[4];
            int y, u, max;

            for (int i = 0; i < b; i++)
            {
                 c = Console.ReadLine();
                for (int j = 0; j < a; j++)
                {
                    if (e[0] < int.Parse(c.Split(' ')[j]))
                    {
                        e[0] = int.Parse(c.Split(' ')[j]);
                        e[1] = j + 1;
                    }
                }
                w[e[1]]++;
                e[0] = -1;
                e[1] = 0;
            }
            for (int k = 0; k < a+1; k++)
            {
                if (e[2] < w[k])
                {
                    e[2]= w[k];
                    e[3] = k;
                }
            }
            Console.WriteLine(e[3]);
        }
    }
}


/*
Author : Shivakkumar K R
File name : 316_Div2_ProbA.cs
*/
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.IO;
public class _316_Div2_ProbA {

	static void Main(string [] args) {
		//Console.SetIn(new StreamReader(File.OpenRead("C://Users//Shiva//Desktop//316_Div2_ProbA.txt")));
		var input = Console.ReadLine().Split(new char[] {' '});
		var n = int.Parse(input[0]); var m = int.Parse(input[1]);

		int [,] cityCandidate = new int[m + 1, n + 1];
		int [] wonCities = new int[n + 1];
		for (int i = 1; i <= m; i++ )
		{
			int firstMax = int.MinValue;
			input = Console.ReadLine().Split(new char[] {' '});
			for (int j = 1; j <= n; j++) {
				cityCandidate[i, j] = int.Parse(input[j - 1]);
				if (firstMax < cityCandidate[i, j]) {
					firstMax = cityCandidate[i, j];
					cityCandidate[i, 0] = j;
				}
			}

			wonCities[cityCandidate[i, 0]]++;
		}

		int secondMax = int.MinValue;
		int secondMaxIndex = 0;
		for (int i = 1; i <= n; i++)
			if (secondMax < wonCities[i]) {
				secondMax = wonCities[i];
				secondMaxIndex = i;
			}

		Console.WriteLine(secondMaxIndex);
	}
}


using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;

namespace codeforces
{
	class Program
	{
		public class User
		{
			public int c;

			public int r;
		}

		public class Comparer : IComparer<User>
		{
			public int Compare(User x, User y)
			{
				if (x.c < y.c)
					return -1;
				return 1;
			}
		}

		public static long getGcd(long a, long b)
		{
			if (b == 0)
				return a;
			return getGcd(b, a % b);
		}

		public static void WriteYESNO(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

		public static List<int> getList(string s)
		{
			return s.Split(' ').Select(int.Parse).ToList();
		}

		private static void Main(string[] args)
		{
/*			var input = new StreamReader("input.txt");
			var output = new StreamWriter("output.txt");*/
			var s = Console.ReadLine();
			var arr = getList(s);
			var n = arr[0];
			var m = arr[1];
			var list = new List<int>();
			for (var i = 0; i < n; ++i)
				list.Add(0);
			for (var i = 0; i < m; ++i)
			{
				s = Console.ReadLine();
				arr = getList(s);
				var winner = 0;
				for (var j = 1; j < n; ++j)
					if (arr[j] > arr[winner])
						winner = j;
				list[winner]++;
			}
			var ans = 0;
			for (var j = 1; j < n; ++j)
				if (list[j] > list[ans])
					ans = j;
			Console.WriteLine(++ans);
			/*			input.Close();
			output.Close();*/
		}
	}
}


using System;
using System.Linq;

namespace _570A
{
    class Program
    {
        static void Main()
        {
            var x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = x[0]; var m = x[1];
            int[] candidates = new int[n];
            for (int i=0;i<m;i++)
            {
                var s = Console.ReadLine().Split().Select(int.Parse).ToArray();

                candidates[Array.IndexOf(s,s.Max())]++;
            }
            Console.WriteLine(Array.IndexOf(candidates,candidates.Max())+1);
        }
    }
}


import java.io.*
import java.util.*

class ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {
    companion object {
        fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))
        fun files(inputFilename: String, outputFilename: String) =
                ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))
    }

    var tok = StringTokenizer("")

    fun close() { rd.close(); wr.close() }
    fun <T> print(v: T) = wr.print(v)
    fun <T> println(v: T) = wr.println(v)
    fun readToken(): String {
        while (!tok.hasMoreTokens()) tok = StringTokenizer(rd.readLine())
        return tok.nextToken()
    }
    fun readLine(): String {
        tok = StringTokenizer("")
        return rd.readLine()
    }
    fun readInt(): Int = readToken().toInt()
    fun readLong(): Long = readToken().toLong()
}

fun main(args: Array<String>) {
    Thread({ val io = ProblemIO.console(); solve(io); io.close() }).start()
}

fun solve(io: ProblemIO) {
    val n = io.readInt()
    val m = io.readInt()
    val c = IntArray(n)
    for (i in 1 .. m) {
        val a = IntArray(n, { io.readInt() })
        val mv = a.max()!!
        val j = a.indices.find({ i -> a[i] == mv })!!
        ++c[j]
    }
    val cmv = c.max()!!
    val res = c.indices.find({ i -> c[i] == cmv })!!
    io.println(res + 1)
}


fun main() {
    val r = System.`in`.bufferedReader()
    val s1 = StringBuilder()
    //val v = r.readLine()!!.split("").filter { it.isNotEmpty() }
    val (n, c) = r.readLine()!!.split(" ").map { it.toInt() }
    val ans = IntArray(n) { 0 }
    repeat(c) {
        //val len = r.readLine()!!.toInt()
        var max = 0
        var index = -1
        val v = r.readLine()!!.split(" ").map { it.toInt() }
        (0..n - 1).forEach {
            if (v[it] > max) {
                max = v[it]
                index = it
            }
        }
        ans[index]++
    }
    var max = 0
    var ind = -1
    (0..n - 1).forEach {
        if (ans[it] > max) {
            max = ans[it]
            ind = it
        }
    }
    println(ind+1)
}


fun main() {
    val r = System.`in`.bufferedReader()
    val s1 = StringBuilder()
    //val v = r.readLine()!!.split("").filter { it.isNotEmpty() }
    val (n, c) = r.readLine()!!.split(" ").map { it.toInt() }
    val ans = IntArray(n) { 0 }
    repeat(c) {
        //val len = r.readLine()!!.toInt()
        var max = -1
        var index = -1
        val v = r.readLine()!!.split(" ").map { it.toInt() }
        (0..n - 1).forEach {
            if (v[it] > max) {
                max = v[it]
                index = it
            }
        }
        ans[index]++
    }
    var max = -1
    var ind = -1
    (0..n - 1).forEach {
        if (ans[it] > max) {
            max = ans[it]
            ind = it
        }
    }
    println(ind+1)
}


import java.util.*
import java.math.*

fun readLn()=readLine()!!
fun readInt()=readLn().toInt()
fun readInts()=readLn().split(" ").map{it.toInt()}
fun readLong()=readLn().toLong()
fun readLongs()=readLn().split(" ").map{it.toLong()}

val out=mutableListOf<String>()
fun printLine(s:String){out.add(s)}
fun output(){println(out.joinToString("\n"))}

fun main(){
    var (n,m)=readInts()
    fun best(cnt:IntArray):Int{
        var ans=0
        for(i in 0 until n)
            if(cnt[i]>cnt[ans])ans=i
        return ans;
    }
    var cnt=IntArray(n){0}
    for(i in 0 until m)cnt[best(readInts().toIntArray())]++
    printLine((best(cnt)+1).toString())
    output()
}


import java.util.*

fun main(args: Array<String>){
    val ( n, m ) = readLine()!!.split(' ').map(String::toInt)
    val cnt = IntArray(n + 1)
    for( k in 1 .. m){
        var id = 1
        var max = 0
        var i = 1
        for( j in readLine()!!.split(' ').map(String::toInt) ){
            if( j > max ){
                max = j
                id = i
            }
            i++
        }
        cnt[id]++
    }
    var id = 1
    var max = 0
    for( i in 1 .. n ){
        if( cnt[i] > max ){
            max = cnt[i]
            id = i
        }
    }
    print( id )
}


fun main() {
    val (numCandidates, numCities) = readLine()!!.split(" ").map { it.toInt() }
    val citiesWon = IntArray(numCandidates) { 0 }
    for (i in 1 until numCities) {
        citiesWon[readLine()!!.split(" ").map { it.toInt() }.toIntArray().firstMax()]++
    }
    print(citiesWon.firstMax() + 1)
}

fun IntArray.firstMax(): Int {
    var maxValue = this[0]
    var maxPos = 0
    for (i in 1 until size) {
        if (this[i] > maxValue) {
            maxPos = i
            maxValue = this[i]
        }
    }
    return maxPos
}


fun main() {
    val (numCandidates, numCities) = readLine()!!.split(" ").map { it.toInt() }
    val citiesWon = IntArray(numCandidates) { 0 }
    for (i in 1 .. numCities) {
        citiesWon[readLine()!!.split(" ").map { it.toInt() }.toIntArray().firstMax()]++
    }
    print(citiesWon.firstMax() + 1)
}

fun IntArray.firstMax(): Int {
    var maxValue = this[0]
    var maxPos = 0
    for (i in 1 until size) {
        if (this[i] > maxValue) {
            maxPos = i
            maxValue = this[i]
        }
    }
    return maxPos
}


import java.util.*

fun main(args: Array<String>){
    val ( n, m ) = readLine()!!.split(' ').map(String::toInt)
    val cnt = IntArray(n + 1)
    for( k in 1 .. m){
        var id = 0
        var max = 0
        var i = 1
        for( j in readLine()!!.split(' ').map(String::toInt) ){
            if( j > max ){
                max = j
                id = i
            }
            i++
        }
        cnt[id]++
    }
    var id = 1
    var max = 0
    for( i in 1 .. n ){
        if( cnt[i] > max ){
            max = cnt[i]
            id = i
        }
    }
    print( id )
}


import java.util.*

fun main(args: Array<String>){
    val ( n, m ) = readLine()!!.split(' ').map(String::toInt)
    val cnt = IntArray(n + 1)
    for( k in 1 .. n){
        var id = 0
        var max = 0
        var i = 1
        for( j in readLine()!!.split(' ').map(String::toInt) ){
            if( j > max ){
                max = j
                id = i
            }
            i++
        }
        cnt[id]++
    }
    var id = 1
    var max = 0
    for( i in 1 .. n ){
        if( cnt[i] > max ){
            max = cnt[i]
            id = i
        }
    }
    print( id )
}


import java.util.*

fun main(args: Array<String>){
    val ( n, m ) = readLine()!!.split(' ').map(String::toInt)
    val cnt = IntArray(n + 1)
    for( k in 1 .. m){
        var id = 0
        var max = 0
        var i = 1
        for( j in readLine()!!.split(' ').map(String::toInt) ){
            if( j > max ){
                max = j
                id = i
            }
            i++
        }
        cnt[id]++
    }
    var id = 0
    var max = 0
    for( i in 1 .. n ){
        if( cnt[i] > max ){
            max = cnt[i]
            id = i
        }
    }
    print( id )
}


import java.util.*

fun main(args: Array<String>){
    val ( n, m ) = readLine()!!.split(' ').map(String::toInt)
    val cnt = IntArray(n + 1)
    for( k in 1 .. n){
        var id = 0
        var max = 0
        var i = 1
        for( j in readLine()!!.split(' ').map(String::toInt) ){
            if( j > max ){
                max = j
                id = i
            }
            i++
        }
        cnt[id]++
    }
    var id = 0
    var max = 0
    for( i in 1 .. n ){
        if( cnt[i] > max ){
            max = cnt[i]
            id = i
        }
    }
    print( id )
}


#include <stdio.h>
#define fi for(i = 1; i < cpn; i++)
#define fj for(i = 0; i < cpm; i++)
int main() {
	int n, m, cpm, cpn, i, j = 0, max, index; scanf("%d%d", &n, &m);
	int a[m], b[n]; cpm = m, cpn = n;
	while(m--){
		n = cpn, i = 0;
		while(n--)	scanf("%d", &a[i++]);
		max = a[0], index = 0;
		fi if(a[i] > max)	max = a[i], index = i;
		b[j++] = index + 1;
	}
	max = b[0];
	fj if(b[i] < max)	max = b[i];
	printf("%d\n", max); return 0;
}


#include <stdio.h>
#define fi for(i = 1; i < cpn; i++)
#define fj for(i = 1; i < cpm; i++)
int main() {
	int n, m, cpm, cpn, i, j = 0, max, index; scanf("%d%d", &n, &m);
	int a[n], b[m]; cpm = m, cpn = n;
	while(m--){
		n = cpn, i = 0;
		while(n--)	scanf("%d", &a[i++]);
		max = a[0], index = 0;
		fi if(a[i] > max)	max = a[i], index = i;
		b[j++] = index + 1;
	}
	max = b[0];
	fj if(b[i] < max)	max = b[i];
	printf("%d\n", max); return 0;
}


#include <stdio.h>
#define fi for(i = 1; i < cpn; i++)
#define fj for(i = 0; i < cpn; i++)
int main() {
	int n, m, cpm, cpn, i, j = 0, max, index; scanf("%d%d", &n, &m);
	int a[n], b[n]; cpm = m, cpn = n; fj b[i] = 0;
	while(m--){
		n = cpn, i = 0;
		while(n--)	scanf("%d", &a[i++]);
		max = a[0], index = 0;
		fi if(a[i] > max)	max = a[i], index = i;
		b[index]++;
	}
	max = b[0], index = 0;
	fj if(b[i] > max)   max = b[i], index = i;
	printf("%d\n", index + 1); return 0;
}


#include <stdio.h>
#define fi for(i = 1; i < cpn; i++)
#define fj for(i = 1; i < cpm; i++)
int main() {
	int n, m, cpm, cpn, i, j = 0, max, index; scanf("%d%d", &n, &m);
	int a[m], b[n]; cpm = m, cpn = n;
	while(m--){
		n = cpn, i = 0;
		while(n--)	scanf("%d", &a[i++]);
		max = a[0], index = 0;
		fi if(a[i] > max)	max = a[i], index = i;
		b[j++] = index + 1;
	}
	max = b[0];
	fj if(b[i] < max)	max = b[i];
	printf("%d\n", max); return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

// ll power(ll a, ll n)
// {
//     ll ans=1;
//     while(n)
//     {
//         if(n&1) ans*=a;
//         a*=a;
//         n>>=1;
//     }
//     return ans;
// }

vector<ll> v[101];
ll mx,d;

void dfs(ll x, ll dis, ll p)
{
    if(dis>d)
    {
        d=dis;
        mx=x;
    }
    for(auto i:v[x])
    {
        if(i==p) continue;
        dfs(i,dis+1,x);
    }
}

int main()
{
    IOS;
    ll n;
    cin>>n;
    ll ans=0;
    repf(i,0,n)
    {
        ll ni;
        cin>>ni;
        d=0;
        mx=-1;
        repf(j,0,ni+1) v[j].clear();
        repf(j,0,ni-1)
        {
            ll x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }
        mx=1;
        dfs(1,0,-1);
        d=0;
        dfs(mx,0,-1);
        ans+=d;
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define intmax 200005
#define nl "\n"
#define mod 1000000007
#define ll long long int

using namespace std;

int maxDeep(vector<int> g[], int indx, int p) {
	int ml = 0;
	FOREACH(it, g[indx]) {
		if(*it == p) continue;
		int l = maxDeep(g, *it, indx);
		if(ml < l) ml = l;
	}
	return ml+1;
}

int main() {
	ios_base::sync_with_stdio(false);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int t,n,u,v,ans=0;
	cin>>t;
	while(t--) {
		vector<int> g[101];
		cin>>n;
		FOR(i, 1, n, 1) {
			cin>>u>>v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		int sing = -1;
		FOR(i, 1, n+1, 1) {
			if(g[i].size() == 1) {
				sing = i;
				break;
			}
		}
		int l = maxDeep(g, sing, -1);
		ans += (l - 1);
	}
	cout<<ans<<nl;

	return 0;
}


#include<bits/stdc++.h>

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define intmax 200005
#define nl "\n"
#define mod 1000000007
#define ll long long int

using namespace std;

int mp = 0;

int maxDeep(vector<int> g[], int indx, int p) {
	// cout<<indx<<" ";
	int ml = 0;
	FOREACH(it, g[indx]) {
		if(*it == p) continue;
		int l = maxDeep(g, *it, indx);
		if(mp < ml+l) {
			mp = ml+l;
		}
		if(ml < l) {
			ml = l;
		}
	}
	// cout<<indx<<": "<<mp<<nl;
	return ml+1;
}

int main() {
	ios_base::sync_with_stdio(false);
	ifstream cin("input.txt");
	ofstream cout("output.txt");

	int t,n,u,v,ans=0;
	cin>>t;
	while(t--) {
		vector<int> g[101];
		cin>>n;
		FOR(i, 1, n, 1) {
			cin>>u>>v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		int sing = -1;
		FOR(i, 1, n+1, 1) {
			if(g[i].size() == 1) {
				sing = i;
				break;
			}
		}
		// cout<<sing<<nl;
		// FOR(i, 1, n+1, 1) {
		// 	cout<<i<<": ";
		// 	FOREACH(it, g[i]) {
		// 		cout<<*it<<" ";
		// 	}
		// 	cout<<nl;
		// }
		mp = 0;
		int l = maxDeep(g, sing, -1);
		// cout<<nl;
		// cout<<l<<nl;
		ans += (mp);
	}
	cout<<ans<<nl;

	return 0;
}


#include<bits/stdc++.h>

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define intmax 200005
#define nl "\n"
#define mod 1000000007
#define ll long long int

using namespace std;

int maxDeep(vector<int> g[], int indx, int p) {
	int ml = 0;
	FOREACH(it, g[indx]) {
		if(*it == p) continue;
		int l = maxDeep(g, *it, indx);
		if(ml < l) ml = l;
	}
	return ml+1;
}

int main() {
	ios_base::sync_with_stdio(false);
	ifstream cin("input.txt");
	ofstream cout("output.txt");

	int t,n,u,v,ans=0;
	cin>>t;
	while(t--) {
		vector<int> g[101];
		cin>>n;
		FOR(i, 1, n, 1) {
			cin>>u>>v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		int sing = -1;
		FOR(i, 1, n+1, 1) {
			if(g[i].size() == 1) {
				sing = i;
				break;
			}
		}
		int l = maxDeep(g, sing, -1);
		ans += (l - 1);
	}
	cout<<ans<<nl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int M = 1e2 + 5;
int in[M], out[M], dp[M];
vector <int> adj[M];

void clear()
{
	memset(in, 0, sizeof(in));
	memset(out, 0, sizeof(out));
	for(int i = 0; i < M; i++)
		adj[i].clear();
}

void dfs1(int node, int par)
{
	in[node] = 0;
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		dfs1(u, node);
		in[node] = max(in[node], 1 + in[u]);
	}
}

void dfs2(int node, int par)
{
	int mx1 = -1, mx2 = -1;
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		if(in[u] >= mx1)
		{
			mx2 = mx1;
			mx1 = in[u];
		}
		else if(in[u] > mx2)	mx2 = in[u];
	}
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		int use = mx1;
		if(mx1 == in[u])	use = mx2;
		out[u] = max(1 + out[node], 2 + use);
		dfs2(u, node);
	}
}

int32_t main()
{
		freopen("in.txt", "r", stdin);
    		freopen("out.txt", "w", stdout);
    	int t;		cin >> t;
    	int ans = 0;
    	while(t--)
    	{
    		int n;		cin >> n;
    		clear();
    		for(int i = 1; i < n; i++)
    		{
    			int u, v;	cin >> u >> v;
    			adj[u].push_back(v);
    			adj[v].push_back(u);
    		}
    		dfs1(1, 0);
    		dfs2(1, 0);
    		int curr = 0;
    		for(int i = 1; i <= n; i++)
    			curr = max(curr, max(in[i], out[i]));
    		// cout << curr << endl;
    		ans += curr;
    	}
    	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int M = 1e2 + 5;
int in[M], out[M];
vector <int> adj[M];

void clear()
{
	memset(in, 0, sizeof(in));
	memset(out, 0, sizeof(out));
	for(int i = 0; i < M; i++)
		adj[i].clear();
}

void dfs1(int node, int par)
{
	in[node] = 0;
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		dfs1(u, node);
		in[node] = max(in[node], 1 + in[u]);
	}
}

void dfs2(int node, int par)
{
	int mx1 = -1, mx2 = -1;
	for(int u : adj[node])
	{
		if(u == par)	continue;
		if(in[u] >= mx1)
		{
			mx2 = mx1;
			mx1 = in[u];
		}
		else if(in[u] > mx2)	mx2 = in[u];
	}
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		int use = mx1;
		if(mx1 == in[u])	use = mx2;
		out[u] = max(1 + out[u], 2 + use);
		dfs2(u, node);
	}
}

int32_t main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    	int t;		cin >> t;
    	int ans = 0;
    	while(t--)
    	{
    		int n;		cin >> n;
    		clear();
    		for(int i = 1; i < n; i++)
    		{
    			int u, v;	cin >> u >> v;
    			adj[u].push_back(v);
    			adj[v].push_back(u);
    		}
    		dfs1(1, -1);
    		dfs2(1, -1);
    		int curr = 0;
    		for(int i = 1; i <= n; i++)
    			curr = max(curr, max(in[i], out[i]));
    		ans += curr;
    	}
    	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int M = 1e2 + 5;
int in[M], out[M];
vector <int> adj[M];

void clear()
{
	memset(in, 0, sizeof(in));
	memset(out, 0, sizeof(out));
	for(int i = 0; i < M; i++)
		adj[i].clear();
}

void dfs1(int node, int par)
{
	in[node] = 0;
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		dfs1(u, node);
		in[node] = max(in[node], 1 + in[u]);
	}
}

void dfs2(int node, int par)
{
	int mx1 = -1, mx2 = -1;
	for(int u : adj[node])
	{
		if(u == par)	continue;
		if(in[u] >= mx1)
		{
			mx2 = mx1;
			mx1 = in[u];
		}
		else if(in[u] > mx2)	mx2 = in[u];
	}
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		int use = mx1;
		if(mx1 == in[u])	use = mx2;
		out[u] = max(1 + out[u], 2 + use);
		dfs2(u, node);
	}
}

int32_t main()
{
    	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
    		freopen("out.txt", "w", stdout);
	#endif
    	ios_base::sync_with_stdio(0);   cin.tie(0);     cout.tie(0);
    	int t;		cin >> t;
    	int ans = 0;
    	while(t--)
    	{
    		int n;		cin >> n;
    		clear();
    		for(int i = 1; i < n; i++)
    		{
    			int u, v;	cin >> u >> v;
    			adj[u].push_back(v);
    			adj[v].push_back(u);
    		}
    		dfs1(1, -1);
    		dfs2(1, -1);
    		int curr = 0;
    		for(int i = 1; i <= n; i++)
    			curr = max(curr, max(in[i], out[i]));
    		ans += curr;
    	}
    	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int M = 1e2 + 5;
int in[M], out[M], dp[M];
vector <int> adj[M];

void clear()
{
	memset(in, 0, sizeof(in));
	memset(out, 0, sizeof(out));
	for(int i = 0; i < M; i++)
		adj[i].clear();
}

void dfs1(int node, int par)
{
	in[node] = 0;
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		dfs1(u, node);
		in[node] = max(in[node], 1 + in[u]);
	}
}

void dfs2(int node, int par)
{
	int mx1 = -1, mx2 = -1;
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		if(in[u] >= mx1)
		{
			mx2 = mx1;
			mx1 = in[u];
		}
		else if(in[u] > mx2)	mx2 = in[u];
	}
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		int use = mx1;
		if(mx1 == in[u])	use = mx2;
		out[u] = max(1 + out[node], 2 + use);
		dfs2(u, node);
	}
}

int32_t main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);   cin.tie(0);     cout.tie(0);
    	int t;		cin >> t;
    	int ans = 0;
    	while(t--)
    	{
    		int n;		cin >> n;
    		clear();
    		for(int i = 1; i < n; i++)
    		{
    			int u, v;	cin >> u >> v;
    			adj[u].push_back(v);
    			adj[v].push_back(u);
    		}
    		dfs1(1, 0);
    		dfs2(1, 0);
    		int curr = 0;
    		for(int i = 1; i <= n; i++)
    			curr = max(curr, max(in[i], out[i]));
    		// cout << curr << endl;
    		ans += curr;
    	}
    	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int M = 1e2 + 5;
int in[M], out[M], dp[M];
vector <int> adj[M];

void clear()
{
	memset(in, 0, sizeof(in));
	memset(out, 0, sizeof(out));
	for(int i = 0; i < M; i++)
		adj[i].clear();
}

void dfs1(int node, int par)
{
	in[node] = 0;
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		dfs1(u, node);
		in[node] = max(in[node], 1 + in[u]);
	}
}

void dfs2(int node, int par)
{
	int mx1 = -1, mx2 = -1;
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		if(in[u] >= mx1)
		{
			mx2 = mx1;
			mx1 = in[u];
		}
		else if(in[u] > mx2)	mx2 = in[u];
	}
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		int use = mx1;
		if(mx1 == in[u])	use = mx2;
		out[u] = max(1 + out[node], 2 + use);
		dfs2(u, node);
	}
}

int32_t main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    	int t;		cin >> t;
    	int ans = 0;
    	while(t--)
    	{
    		int n;		cin >> n;
    		clear();
    		for(int i = 1; i < n; i++)
    		{
    			int u, v;	cin >> u >> v;
    			adj[u].push_back(v);
    			adj[v].push_back(u);
    		}
    		dfs1(1, 0);
    		dfs2(1, 0);
    		int curr = 0;
    		for(int i = 1; i <= n; i++)
    			curr = max(curr, max(in[i], out[i]));
    		// cout << curr << endl;
    		ans += curr;
    	}
    	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int M = 1e2 + 5;
int in[M], out[M];
vector <int> adj[M];

void clear()
{
	memset(in, 0, sizeof(in));
	memset(out, 0, sizeof(out));
	for(int i = 0; i < M; i++)
		adj[i].clear();
}

void dfs1(int node, int par)
{
	in[node] = 0;
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		dfs1(u, node);
		in[node] = max(in[node], 1 + in[u]);
	}
}

void dfs2(int node, int par)
{
	int mx1 = -1, mx2 = -1;
	for(int u : adj[node])
	{
		if(u == par)	continue;
		if(in[u] >= mx1)
		{
			mx2 = mx1;
			mx1 = in[u];
		}
		else if(in[u] > mx2)	mx2 = in[u];
	}
	for(auto u : adj[node])
	{
		if(u == par)	continue;
		int use = mx1;
		if(mx1 == in[u])	use = mx2;
		out[u] = max(1 + out[u], 2 + use);
		dfs2(u, node);
	}
}

int32_t main()
{
    	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
    		freopen("output.txt", "w", stdout);
	#endif
    	ios_base::sync_with_stdio(0);   cin.tie(0);     cout.tie(0);
    	int t;		cin >> t;
    	int ans = 0;
    	while(t--)
    	{
    		int n;		cin >> n;
    		clear();
    		for(int i = 1; i < n; i++)
    		{
    			int u, v;	cin >> u >> v;
    			adj[u].push_back(v);
    			adj[v].push_back(u);
    		}
    		dfs1(1, -1);
    		dfs2(1, -1);
    		int curr = 0;
    		for(int i = 1; i <= n; i++)
    			curr = max(curr, max(in[i], out[i]));
    		ans += curr;
    	}
    	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
#include <stdint.h>
using namespace std;

#define int long long
#define pb push_back
#define mod 1000000007
#define endl '\n'
#define w(x) int x;cin>>x; while(x-->0)
#define memset(var,val) memset(var,val,sizeof(var))
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
// #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
// #endif
}
vector<vector<int>>node(101);
bool visited[101] = {false};
int dp[101];
int dfs(int i)
{
    if (dp[i] != -1)
        return dp[i];

    visited[i] = true;
    int ans = 0;
    for (int a : node[i])
    {
        if (!visited[a])
            ans = max(ans, dfs(a) + 1);
    }
    return dp[i] = ans;
}

void mysol()
{
    int ans = 0;
    w(spider)
    {
        int n; cin >> n;
        int max_len = 0;
        for (int i = 1; i < n; i++)
        {
            int a, b; cin >> a >> b;
            node[a].pb(b);
            node[b].pb(a);
        }
        memset(dp, -1);
        for (int i = 1; i <= n; i++) {
            max_len = max(max_len, dfs(i));
            memset(visited, false);
        }
        ans += max_len;
        for (auto &a : node)
            a.clear();
    }
    cout << ans;
}

int32_t main()
{
    fast();
    // w(t)
    {
        mysol();
    }
    //cerr << sizeof(dp)*(1e-6) << " megabytes\n";
    return 0;
}


#include<bits/stdc++.h>
#include <stdint.h>
using namespace std;

#define int long long
#define pb push_back
#define mod 1000000007
#define endl '\n'
#define w(x) int x;cin>>x; while(x-->0)
#define memset(var,val) memset(var,val,sizeof(var))
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
// #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
// #endif
}
vector<vector<int>>node(101);
bool visited[101] = {false};
int dfs(int i)
{
    visited[i] = true;
    int ans = 0;
    for (int a : node[i])
    {
        if (!visited[a])
            ans = max(ans, dfs(a) + 1);
    }
    return ans;
}

void mysol()
{
    int ans = 0;
    w(spider)
    {
        int n; cin >> n;
        int max_len = 0;
        for (int i = 1; i < n; i++)
        {
            int a, b; cin >> a >> b;
            node[a].pb(b);
            node[b].pb(a);
        }
        for (int i = 1; i <= n; i++) {
            max_len = max(max_len, dfs(i));
            memset(visited, false);
        }
        ans += max_len;
        for (auto &a : node)
            a.clear();
    }
    cout << ans;
}

int32_t main()
{
    fast();
    // w(t)
    {
        mysol();
    }
    //cerr << sizeof(dp)*(1e-6) << " megabytes\n";
    return 0;
}


#include<bits/stdc++.h>
#include <stdint.h>
using namespace std;

#define int long long
#define pb push_back
#define mod 1000000007
#define endl '\n'
#define w(x) int x;cin>>x; while(x-->0)
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}
vector<vector<int>>node(101);
bool visited[101] = {false};
int dfs(int i)
{
    visited[i] = true;
    int ans = 0;
    for (int a : node[i])
    {
        if (!visited[a])
            ans = max(ans, dfs(a) + 1);
    }
    return ans;
}

void mysol()
{
    int ans = 0;
    w(spider)
    {
        int n; cin >> n;
        int max_len = 0;
        for (int i = 1; i < n; i++)
        {
            int a, b; cin >> a >> b;
            node[a].pb(b);
            node[b].pb(a);
        }
        for (int i = 1; i <= n; i++) {
            max_len = max(max_len, dfs(i));
            memset(visited, false, sizeof (visited));
        }
        ans += max_len;
        memset(visited, false, sizeof (visited));
        for (auto &a : node)
            a.clear();
    }
    cout << ans;
}

int32_t main()
{
    fast();
    // w(t)
    {
        mysol();
    }
    //cerr << sizeof(dp)*(1e-6) << " megabytes\n";
    return 0;
}


#include<bits/stdc++.h>
#include <stdint.h>
using namespace std;

#define int long long
#define pb push_back
#define mod 1000000007
#define endl '\n'
#define w(x) int x;cin>>x; while(x-->0)
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
vector<vector<int>>node(101);
bool visited[101] = {false};
int dfs(int i)
{
    visited[i] = true;
    int ans = 0;
    for (int a : node[i])
    {
        if (!visited[a])
            ans = max(ans, dfs(a) + 1);
    }
    return ans;
}

void mysol()
{
    int ans = 0;
    w(spider)
    {
        int n; cin >> n;
        int max_len = 0;
        for (int i = 1; i < n; i++)
        {
            int a, b; cin >> a >> b;
            node[a].pb(b);
            node[b].pb(a);
        }
        for (int i = 1; i <= n; i++) {
            max_len = max(max_len, dfs(i));
            memset(visited, false, sizeof (visited));
        }
        ans += max_len;
        memset(visited, false, sizeof (visited));
        for (auto &a : node)
            a.clear();
    }
    cout << ans;
}

int32_t main()
{
    fast();
    // w(t)
    {
        mysol();
    }
    //cerr << sizeof(dp)*(1e-6) << " megabytes\n";
    return 0;
}