#include <stdlib.h>
#include <stdio.h>
int main()
{
int n, t;
while (scanf("%d%d", &n, &t) != EOF) {
int total[20] = {0};
int m, s;
int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < t; j++) {
scanf("%d:%d", &m, &s);
total[j] += (m * 60) + s;
}
//Bubble Sort
for (i = 0; i < t - 1; i++)
for (j = 0;j < t - 1 - i; j++) {
//total[0] will be minimum
if (total[j] > total[j + 1]) {
/* xor change
total[j] ^= total[j + 1];
total[j + 1] ^= total[j];
total[j] ^= total[j + 1];
*/
int temp = total[j];
total[j] = total[j + 1];
total[j + 1] = temp;
}
}
for (i = 0; i < t; i++)
printf("%d\n", total[i]);
}
return 0;
}