#include <iostream>

using namespace std;

int main()
{
    int h,n;
    cin >> h >> n;

    int** steneIProlazi = new int*[h+1];
    int** protok = new int*[h+1];

    for (int i = 0; i <= h; ++i)
    {
        steneIProlazi[i] = new int[n];
        protok[i] = new int[n];
    }

    for (int i = 1; i <= h; ++i)
        for (int j = 0; j < n; ++j)
        cin >> steneIProlazi[i][j];

    for (int i = 0; i <= h; ++i)
        for (int j = 0; j < n; ++j)
        protok[i][j] = 0;

    for (int i = 0; i < n; ++i)
        protok[0][i] = 1;

    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
        cout << protok[i][j];
        if (steneIProlazi[i+1][j] == 1) protok[i+1][j] += protok[i][j];                           //1.
        if ((steneIProlazi[i+1][j] == 0) && (j+1<n) && (j>0) && (steneIProlazi[i+1][j+1] == 1) && (steneIProlazi[i+1][j-1] == 1) && (protok[i][j] % 2 == 0)) //.2
        {
        protok[i+1][j+1] += protok[i][j]/2;
        protok[i+1][j-1] += protok[i][j]/2;
        }
        if ((steneIProlazi[i+1][j] == 0) && (j+1<n) && (j>0) && (steneIProlazi[i+1][j+1] == 1) && (steneIProlazi[i+1][j-1] == 1) && (protok[i][j] % 2 == 1) && ((i+1) % 2 == 0))
        {
        protok[i+1][j+1] += protok[i][j]/2+1;
        protok[i+1][j-1] += protok[i][j]/2;
        }
        if ((steneIProlazi[i+1][j] == 0) && (j+1<n) && (j>0) && (steneIProlazi[i+1][j+1] == 1) && (steneIProlazi[i+1][j-1] == 1) && (protok[i][j] % 2 == 1) && ((i+1) % 2 == 1))
        {
        protok[i+1][j+1] += protok[i][j]/2;
        protok[i+1][j-1] += protok[i][j]/2+1;
        }
        if ((steneIProlazi[i+1][j] == 0) && (j == 0) && (steneIProlazi[i+1][j+1] == 1))
        protok[i+1][j+1] += protok[i][j];
        if ((steneIProlazi[i+1][j] == 0) && (j == n-1) && (steneIProlazi[i+1][j-1] == 1))
        protok[i+1][j-1] += protok[i][j];
//GORE RADI
        int suma{0};
        int k{0};
        if ((steneIProlazi[i+1][j] == 0) && (j<n-1) && (steneIProlazi[i+1][j+1] == 0))
            for (k = j; k < n; ++k)
            {
            if (steneIProlazi[i+1][k] == 0)
            suma += protok[i][k];
            else break;
            }
        if ((suma > 0) && (k == n)) { protok[i+1][j-1] += suma; break; }                        //4.
        else if ((suma > 0) && (j == 0)) { protok[i+1][k] += suma; j = k-1; }                        //5.
        else if ((suma > 0) && (suma % 2 == 0))                                                 //6.
        {
            protok[i+1][j-1] += suma/2;
            protok[i+1][k] += suma/2;
            j = k-1;
        }
        else if ((suma > 0) && (suma % 2 == 1) && ((i+1) % 2 == 0))                                                         //7.
        {
            protok[i+1][j-1] += suma/2;
            protok[i+1][k] += suma/2 + 1;
            j = k-1;
        }
        else if ((suma > 0) && (suma % 2 == 1) && ((i+1) % 2 == 1))                                                    //8.
        {
            protok[i+1][j-1] += suma/2 + 1;
            protok[i+1][k] += suma/2;
            j = k-1;
      }
        }
            cout << '\n';
    }


    for (int i = 0; i < n; ++i)
        cout << protok[h][i] << " ";

    for (int i = 0; i <= h; ++i)
    {
        delete[] steneIProlazi;
        delete[] protok;
    }
    return 0;
}