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

namespace AOJ0505Questionnaire
{
    class Program
    {
        static void Main(string[] args)
        {
            var outputs = new List<string>();

            while (true)
            {
                var readLine = Console.ReadLine();
                var inputs = readLine.Split(' ');
                var numberOfStudents = int.Parse(inputs[0]);
                var numberOfDestinationCandidates = int.Parse(inputs[1]);

                if (numberOfStudents == 0 && numberOfDestinationCandidates == 0 || outputs.Count >= 5)
                {
                    break;
                }

                var summary = new int[numberOfDestinationCandidates];
                CreateSummary(numberOfStudents, summary);

                var numberOfVotes = new List<int>[numberOfStudents + 1];
                int minNumberOfVotes;
                int maxNumberOfVotes;
                SortNumberOfVotes(summary, numberOfDestinationCandidates, numberOfStudents, numberOfVotes, out minNumberOfVotes, out maxNumberOfVotes);

                outputs.Add(CreateOutput(numberOfVotes, minNumberOfVotes, maxNumberOfVotes));
            }

            foreach(var output in outputs)
            {
                Console.WriteLine(output);
            }

            Console.Read(); // To keep to display the output window
        }

        public static int ToInt(char character)
        {
            return character - '0';
        }

        private static void CreateSummary(int numberOfStudents, int[] summary)
        {
            for (var i = 0; i < numberOfStudents; ++i)
            {
                var questionnaireResult = Console.ReadLine();
                var preferences = questionnaireResult.Split(' ');
                for (var j = 0; j < preferences.Length; ++j)
                {
                    summary[j] += int.Parse(preferences[j]);
                }
            }
        }

        private static void SortNumberOfVotes(int[] summary, int numberOfDestinationCandidates, int numberOfStudents, List<int>[] numberOfVotes, out int minNumberOfVotes, out int maxNumberOfVotes)
        {
            minNumberOfVotes = numberOfStudents;
            maxNumberOfVotes = 0;

            for (var i = 0; i < numberOfDestinationCandidates; ++i)
            {
                if (numberOfVotes[summary[i]] == null)
                {
                    numberOfVotes[summary[i]] = new List<int>();
                }

                if(minNumberOfVotes > summary[i])
                {
                    minNumberOfVotes = summary[i];
                }

                if (maxNumberOfVotes < summary[i])
                {
                    maxNumberOfVotes = summary[i];
                }

                numberOfVotes[summary[i]].Add(i + 1);
            }
        }

        private static string CreateOutput(List<int>[] numberOfVotes, int minNumberOfVotes, int maxNumberOfVotes)
        {
            var output = new StringBuilder();

            for (var i = maxNumberOfVotes; i >= minNumberOfVotes; --i)
            {
                if (numberOfVotes[i] != null)
                {
                    var length = numberOfVotes[i].Count;
                    for (var j = 0; j < length; ++j)
                    {
                        output.Append(numberOfVotes[i][j]);

                        if(i > minNumberOfVotes || j < length - 1)
                        {
                            output.Append(' ');
                        }
                    }
                }
            }

            return output.ToString();
        }

    }
}


Measured memory_bytes: 18004