using System;

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
            var h = int.Parse(Console.ReadLine());
            var n = int.Parse(Console.ReadLine());
            int[,] matrica = new int[h, n];
            string red;
            for (int i = 0; i < h; i++)
            {
                red = Console.ReadLine();
                for (int j = 0; j < n; j++)
                    matrica[i, j] = red[j] - '0';

            }
            for (int i = 0; i < h - 1; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if(matrica[i, j] > 0)
                    {
                        if(matrica[i + 1, j] > 0)
                        {
                            matrica[i + 1, j] -= 1;
                            matrica[i + 1, j] += matrica[i, j];
                        }
                        else
                        {
                            bool levi = false;
                            bool desni = false;
                            int lindex = 0;
                            int dindex = 0;
                            for (int k = 1; k < n; k++)
                            {
                                if (!levi && !desni)
                                {
                                    if (j - k >= 0 && !levi)
                                    {
                                        if (matrica[i + 1, j - k] > 0)
                                        {
                                            levi = true;
                                            lindex = j - k;
                                        }
                                    }
                                    if (j + k < n && !desni)
                                    {
                                        if (matrica[i + 1, j + k] > 0)
                                        {
                                            desni = true;
                                            dindex = j + k;
                                        }
                                    }
                                }
                                else break;
                            }
                            
                            if (levi && desni)
                            {
                                matrica[i + 1, lindex] += matrica[i, j] / 2;
                                matrica[i + 1, dindex] += matrica[i, j] / 2;
                                if (matrica[i, j] % 2 != 0)
                                {
                                    if (i + 1 % 2 == 0)
                                    {
                                        matrica[i + 1, dindex] += 1;
                                    }
                                    else
                                    {
                                        matrica[i + 1, lindex] += 1;
                                    }
                                }
                            }
                            else if (levi)
                            {
                                //matrica[i + 1, lindex] -= 1;
                                matrica[i + 1, lindex] += matrica[i, j];
                            }
                            else if (desni)
                            {
                                //matrica[i + 1, lindex] -= 1;
                                matrica[i + 1, dindex] += matrica[i, j];
                            }
                            Console.WriteLine();
                            for (int y = 0; y < h; y++)
                            {
                                for (int u = 0; u < n; u++)
                                    Console.Write(matrica[y, u]);
                                Console.WriteLine();
                            }
                            Console.WriteLine();
                        }
                    }
                    else
                    {
                        if(matrica[i + 1, j] > 0)
                            matrica[i + 1, j] -= 1;
                    }
                }
            }
            for (int j = 0; j < n; j++)
                Console.Write(matrica[h - 1, j]);
        }
    }
}