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

namespace ConsoleApp18
{
    class Program
    {
      
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int h = int.Parse(Console.ReadLine());
            int[,] a = new int[n, h];
            int[] a2= new int[h];
            int[] nl = new int[h];
            int[] nd = new int[h];
            int t = 0;
            int l=0;
            int d = 0;
            int pi=0;
            int pj = 0;
            for (int i = 0; i < n; i++)
            {
                string[] rec = Console.ReadLine().Split();
                for (int j = 0; j < h; j++)
                {
                    a[i, j] = int.Parse(rec[j]);
                }
            }
            for (int i = 0; i < n; i++)
            {

                if (i == 0)
                {
                   
                        for (int j = h - 1; j >= 0; j--)
                        {
                            //Console.WriteLine("neparan " + t);
                            if (a[i, j] == 0) t++;
                            else if(a[i,j]==1)
                            {
                                a[i, j] = a[i, j] + t;
                                t = 0;
                                pi = i;
                                pj = j;
                                //Console.WriteLine("Pros1");
                            }
                            if (j == 0) { a[pi, pj] = a[pi, pj] + t; t = 0;a2[pj] = a[i, pj]; }
                            a2[j] = a[i, j];
                        
                        }

                   

              /*    for (int p = 0; p < h; p++)
                    {
                        Console.Write(a2[p]+"  ");
                    }
                    Console.ReadLine();*/
                
            }
                else
                {



                    if (i % 2 == 0)
                    {



                        for (int j = h - 1; j >= 0; j--)
                        {
                            if (a[i, j] == 0 /*j != h - 1*/)
                            {
                                nd[j] = a2[j]/2; l = l + a2[j] / 2 + a2[j] % 2; /*Console.WriteLine(l+" sfdas "+t +" "+a2[j]);*/
                            }
                            else if (a[i, j] == 1)
                            {
                                a[i, j] = l  + a2[j]+1;
                              //Console.WriteLine( "fasfa "+ l +" "+a[i,j]+" "+a2[j]);
                                pi = i;
                                pj = j;
                                l = 0;
                                //Console.WriteLine("Pros " + t);
                            }
                            if (j == 0 && a[i, j] == 0)
                            {//Console.WriteLine(" sad" + t+" " +a2[j]);
                                a2[pj] = a[pi, pj] + l-1;
                               //Console.WriteLine("Prsados " + pi + " " + pj + " " + a[i, j] + " " + a[pi, pj] + " " + l + " " + a2[j]);
                                l = 0;

                                //a2[pj] = a[pi, pj]-1;
                            }

                            if (a[i, j] != 0)
                                a2[j] = a[i, j] - 1;
                            else a2[j] = a[i, j];

                        }
                        for (int j = 0; j < h; j++)
                        {
                            if (a[i,j] == 0) d = nd[j] + d;
                            else if (a[i,j] != 0) { a2[j] = a2[j] + d; pj = j; /*Console.WriteLine(" fas " + d);*/ d = 0; }
                            if (j == h-1 && a[i, j] == 0)  { a2[pj] = a2[pj] + d; d = 0; }

                        }

                       /* for (int p = 0; p < h; p++)
                        {
                            Console.Write(a2[p] + "  ");
                        }
                        Console.ReadLine();
                        */
                    }
                





                    if (i % 2 != 0)
                    {
                        for (int j = 0; j < h; j++)
                        {
                            if (a[i, j] == 0 /*j != h - 1*/)
                            {
                                nl[j] = a2[j] / 2; d = d+a2[j] / 2 + a2[j]%2; /*Console.WriteLine(d+" "+t +" "+a2[j]+" "+nl[j]);*/
                            }
                            else if (a[i, j] == 1)
                            {
                                a[i,j] = d+a2[j]+1;
                              // Console.WriteLine( "kdf "+ d +" "+a[i,j]+" "+a2[j]+" "+j);
                                 pi = i;
                                pj = j;
                                d = 0;
                               // Console.WriteLine("Pros " + t);
                            }
                          if (j == h - 1 && a[i,j]==0)
                            {//*Console.WriteLine(" sad" + t+" " +a2[j]);
                                a2[pj] = a[pi, pj] + d-1 ;
                                //Console.WriteLine("Prsados " + pi + " " + pj + " " + a[i, j] + " " + a[pi, pj] + " " + d + " " + a2[j]);
                                d = 0;
                               // Console.WriteLine("uso1");
                               
                            }
                            if (a[i, j] != 0)
                                a2[j] = a[i, j] - 1;
                            else a2[j] = a[i, j];
                        }
                        for (int j = h - 1; j >= 0; j--)
                        {
                            if (a[i,j] == 0) {l = nl[j] + l; /*Console.WriteLine(" " + l + "  " + j);*/ }
                            else if (a[i,j] != 0) { a2[j] = a2[j] + l; pj = j; /*Console.WriteLine(" " + l+ "  "+pj); */l = 0; }
                            if (j == 0 && a[i,j] == 0) { a2[pj] = a2[pj] + l;/*Console.WriteLine("uso2"+l+" "+pj);*/l = 0; }
                           
                            }

                  /*  for (int p = 0; p < h; p++)
                    {
                        Console.Write(a2[p] + "  ");
                    }
                    Console.ReadLine();*/

                }
            



                }
            }
            for(int i = 0; i < h; i++)
            {
                Console.Write(a2[i]+" ");
            }
            Console.ReadLine();
        }
    }
}