#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int h, n;
    cin >> h >> n;
    int vodopad[h][n];
    for(int i=0; i<h; i++)
        for(int j=0; j<n; j++)
            cin >> vodopad[i][j];
    for(int i=0; i<h; i++)
        for(int j=0; j<n; j++)
        {
            if((vodopad[i][j] == 0 || vodopad[i][j] <0) && i!=0 && i!=h)
            {
                if(j == n-1)
                {
                    if(vodopad[i][j-1] == 0)
                        vodopad[i][j-1]-=abs(vodopad[i-1][j]);
                    else
                        vodopad[i][j-1]=abs(vodopad[i-1][j]);
                }

                else if(j == 0)
                {
                    if(vodopad[i][j+1] == 0)
                        vodopad[i][j+1]-=abs(vodopad[i-1][j]);
                    else
                    {
                        vodopad[i][j+1]=abs(vodopad[i-1][j]);
                    }


                }

                else
                {
                    if(vodopad[i-1][j]%2 == 0)
                    {
                        if(vodopad[i][j-1] == 0)
                            vodopad[i][j-1]-=abs(vodopad[i-1][j])/2;
                    else
                        if(vodopad[i-1][j-1] !=0)
                            vodopad[i][j-1]+=abs(vodopad[i-1][j])/2;
                        else vodopad[i][j-1]+=abs(vodopad[i-1][j]/2-1);

                    if(vodopad[i][j+1] == 0)
                        vodopad[i][j+1]-=abs(vodopad[i-1][j])/2;
                    else
                        if(vodopad[i-1][j+1] !=0)
                            vodopad[i][j+1]+=abs(vodopad[i-1][j])/2;
                        else vodopad[i][j+1]+=abs(vodopad[i-1][j]/2-1);
                    }

                    else if(vodopad[i-1][j]%2 != 0 && i%2==1)
                    {
                        if(vodopad[i][j-1] == 0)
                        vodopad[i][j-1]-=abs(vodopad[i-1][j])/2;
                    else
                        if(vodopad[i-1][j-1] !=0)
                            vodopad[i][j-1]+=abs(vodopad[i-1][j])/2;
                        else vodopad[i][j-1]+=abs(vodopad[i-1][j]/2-1);

                    if(vodopad[i][j+1] == 0)
                        vodopad[i][j+1]-=abs(vodopad[i-1][j])/2+1;
                    else
                        if(vodopad[i-1][j+1] !=0)
                            vodopad[i][j+1]+=abs(vodopad[i-1][j])/2+1;
                        else vodopad[i][j+1]+=abs(vodopad[i-1][j]/2+1-1);


                    }else if(vodopad[i-1][j]%2 != 0 && i%2==0)
                    {
                        if(vodopad[i][j-1] == 0)
                        vodopad[i][j-1]-=abs(vodopad[i-1][j])/2+1;
                    else
                        if(vodopad[i-1][j-1] !=0)
                            vodopad[i][j-1]+=abs(vodopad[i-1][j])/2+1;
                        else vodopad[i][j-1]+=abs(vodopad[i-1][j]/2+1-1);

                    if(vodopad[i][j+1] == 0)
                        vodopad[i][j+1]-=abs(vodopad[i-1][j])/2;
                    else
                        if(vodopad[i-1][j+1]!=0)
                            vodopad[i][j+1]+=abs(vodopad[i-1][j])/2;
                        else vodopad[i][j+1]+=abs(vodopad[i-1][j]/2-1);
                    }

                }
            }
            else if((vodopad[i][j] == 0 || vodopad[i][j] <0) && i==0)
            {
                if(j == n-1)
                {
                    if(vodopad[i][j-1] == 0)
                        vodopad[i][j-1]-=1;
                    else
                        vodopad[i][j-1]+=1;
                }

                else if(j == 0)
                {
                    if(vodopad[i][j+1] == 0)
                        vodopad[i][j+1]-=1;
                    else
                        vodopad[i][j+1]+=1;
                }

                else
                {
                    if(vodopad[i+1][j-1] == 0)
                        vodopad[i+1][j-1]-=1;
                    else
                        vodopad[i+1][j-1]+=1;

                    if(vodopad[i+1][j+1] == 0)
                        vodopad[i+1][j+1]-=1;
                    else
                        vodopad[i+1][j+1]+=1;
                }
            }else if(vodopad[i][j] >=2)
            {
                if(vodopad[i+1][j]!=0)
                    vodopad[i+1][j] = abs(vodopad[i][j]);
            }
        }

    for(int i=0;i<n;i++)
        cout << abs(vodopad[h-1][i]);
    return 0;
}