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

namespace Vodopad
{
    class Program
    {
        static int[,] Met(int h, int n, int i, int j, int[,] a, int[,] b)
        {

            if (a[i, j] == 0)
            {
                if (j == 0)
                {
                    for (int k1 = j + 1; k1 < n; k1++)
                    {
                        if (a[i, k1] == 1)
                        {
                            b[i, k1] += 1;
                            return b;
                        }
                    }
                }
                else if (j == n - 1)
                {
                    for (int k = j; k >= 0; k--)
                    {
                        if (a[i, k] == 1)
                        {
                            b[i, k] += 1;
                            return b;
                        }
                    }
                }
                else
                {
                    for (int k = j - 1; k >= 0; k--)
                    {
                        if (a[i, k] == 1)
                        {
                            b[i, k] += 1;
                            return b;
                        }
                        else if (k == 0)
                        {
                            for (int k1 = j + 1; k1 < n; k1++)
                            {
                                if (a[i, k1] == 1)
                                {
                                    b[i, k1] += 1;
                                    return b;
                                }
                            }
                        }
                    }
                }
            }
            else b[i, j] += 1;
            return b;
        }
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int h = int.Parse(s[0]);
            int n = int.Parse(s[1]);
            int[,] a = new int[h, n];
            for (int i = 0; i < h; i++)
            {
                s = Console.ReadLine().Split();
                for (int j = 0; j < n; j++)
                {
                    a[i, j] = int.Parse(s[j]);
                }
            }
            int[,] b = new int[h, n];
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    b[i, j] = 0;
                }
            }
            for (int i = 0; i < 1; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    Met(h, n, i, j, a, b);
                }
            }
            for (int i = 1; i < h; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (b[i - 1, j] != 0)
                    {
                        if (a[i, j] == 1) b[i, j] += b[i - 1, j];
                        else
                        {
                            if (b[i - 1, j] > 1)
                            {
                                int k1 = b[i - 1, j] / 2;
                                int k2 = b[i - 1, j] / 2;
                                if ((i + 1) % 2 == 0 && b[i-1,j]%2==1) k2++;//paran
                                else if ((i + 1) % 2 == 1 && b[i - 1, j] % 2 == 1) k1++;
                                while(k1!=0 || k2!=0)
                                {
                                    for (int k = j+1; k <= n; k++)
                                    {
                                        if(k==n)
                                        {
                                            for (int k3 = j-1; k3 >= -1 ; k3++)
                                            {
                                                if(a[i,k3]==1)
                                                {
                                                    b[i, k3] += k2;
                                                    k2 = 0;
                                                    break;
                                                }
                                            }
                                            break;
                                        }
                                        else if(a[i,k]==1)
                                        {
                                            b[i, k] += k2;
                                            k2 = 0;
                                            break;
                                        }
                                        
                                    }
                                    for (int k3 = j - 1; k3 >= -1; k3++)
                                    {
                                        if (k3==-1)
                                        {
                                            for (int k = 0; k < n; k++)
                                            {
                                                if (a[i, k] == 1)
                                                {
                                                    b[i, k] += k1;
                                                    k1 = 0;
                                                    break;
                                                }
                                            }
                                            break;
                                        }
                                        else if (a[i,k3]==1)
                                        {
                                            b[i, k3] += k1;
                                            k1 = 0;
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if ((i + 1) % 2 == 0)
                                {
                                    for (int k = j + 1; k <= n; k++)
                                    {
                                        if (k == n)
                                        {
                                            for (int k3 = j - 1; k3 >= -1; k3++)
                                            {
                                                if (a[i, k3] == 1)
                                                {
                                                    b[i, k3] += 1;
                                                    break;
                                                }
                                            }
                                            break;
                                        }
                                        else if (a[i, k] == 1)
                                        {
                                            b[i, k] += 1;
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    for (int k3 = j - 1; k3 >= -1; k3++)
                                    {
                                        if (k3 == -1)
                                        {
                                            for (int k4 = 0; k4 < n; k4++)
                                            {
                                                if (a[i, k4] == 1)
                                                {
                                                    b[i, k4] += 1;
                                                    break;
                                                }
                                            }
                                            break;
                                        }
                                        else if (a[i, k3] == 1)
                                        {
                                            b[i, k3] += 1;
                                            break;
                                        }
                                    }
                                }
                            }

                        }
                    }
                }
            }
            for (int i = h-1; i < h; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    Console.Write(b[i, j] + " ");
                }
                Console.WriteLine();
            }
        }
    }
}