#include <iostream>

using namespace std;

class polje
{
    public:
        int br;
        bool nula;
};




int main()
{
    int h,n, kolicina1, kolicina2;
    cin >>h >>n;
    polje mat[h+1][n];
    polje niz[n];
    for (int i = 0; i<n; i++) mat[0][i].br = 1;
    for (int i = 1; i<h+1; i++)
        for (int j = 0; j<n; j++)
            {
                cin >> mat[i][j].br;
                if (mat[i][j].br == 0) mat[i][j].nula = true;
                else mat[i][j].nula = false;
            }
    for (int i = 1; i<h+1; i++)
        {
            for (int j = 0; j<n; j++)
            {

                mat[i][j].br = mat[i-1][j].br;
            }
            for (int br = 0; br<n; br++) niz[br] = mat[i][br];

            for (int a = 0; a<n; a++)
            {
                if (niz[a].nula && niz[a].br!=0)
                {
                    int pomeraj = -1;
                    int pomeraj2 = 1;
                    kolicina1 = (niz[a].br/2) + (niz[a].br&1);
                    kolicina2 = niz[a].br - kolicina1;
                    niz[a].br = 0;
                    if (i&1)
                    {
                        int m = a, m2 = a;;
                        while(niz[m].nula)
                        {
                            if (m == 0) pomeraj = -pomeraj;
                            niz[m+pomeraj].br = niz[m+pomeraj].br + kolicina1;
                            kolicina1=niz[m+pomeraj].br;
                            niz[m].br = 0;
                            m+=pomeraj;
                        }
                        while(niz[m2].nula && kolicina2!=0)
                        {
                            if (m2==n-1) pomeraj2 = -pomeraj2;
                            niz[m2+pomeraj2].br = niz[m2+pomeraj2].br + kolicina2;
                            kolicina2=niz[m2+pomeraj2].br;

                            niz[m2].br = 0;
                            m2+=pomeraj2;
                        }
                    }
                    else
                    {
                        int m = a, m2 = a;
                        while (niz[m].nula && kolicina2!=0)
                        {
                            if (m == 0) pomeraj = -pomeraj;
                            niz[m+pomeraj].br = niz[m+pomeraj].br + kolicina2;
                            kolicina2=niz[m+pomeraj].br;
                            niz[m].br = 0;
                            m+=pomeraj;
                        }
                        while(niz[m2].nula)
                        {
                            if (m2==n-1) pomeraj2 = -pomeraj2;
                            niz[m2+pomeraj2].br = niz[m2+pomeraj2].br + kolicina1;
                            niz[m2].br = 0;
                            kolicina1 = niz[m2+pomeraj2].br;
                            m2+=pomeraj2;
                        }
                    }
                }
            }
            for (int b = 0; b<n; b++) mat[i][b]= niz[b];

        }

        for (int i = 1; i<h+1; i++)
            {
                for (int j = 0; j<n; j++)
                    cout <<mat[i][j].br <<" ";
                cout <<endl;
            }

    return 0;
}