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

namespace ConsoleApplication4
{
    class Program
    {

        static void Main(string[] args)
        {
            var input1 = Console.ReadLine().Split().Select(x => int.Parse(x.ToString())).ToArray();
            var num = new string[input1[0],input1[1]];

            int i,j;
            for (i = 1; i <= input1[0]; i++)
            { 
                var inputL = Console.ReadLine().Split().ToArray().First().ToCharArray();
                for(j = 1; j<= input1[1]; j++)
                {
                    num[i-1, j-1] = inputL[j - 1].ToString().Replace(".","0");
                }
            }

            for (i = 0; i < input1[0]; i++)
            {
                for (j = 0; j < input1[1]; j++)
                {
                    if (num[i, j].StartsWith("#"))
                    {
                        try
                        {
                            num[i - 1, j - 1] = num[i - 1, j - 1] + 1;
                        }
                        catch (System.IndexOutOfRangeException e)
                        { }
                        try
                        {
                            num[i - 1, j] = num[i - 1, j] + 1;
                        }
                        catch (System.IndexOutOfRangeException e)
                        { }
                        try
                        {
                            num[i - 1, j + 1] = num[i - 1, j + 1] + 1;
                        }
                        catch (System.IndexOutOfRangeException e)
                        { }
                        try
                        {
                            num[i, j - 1] = num[i, j - 1] + 1;
                        }
                        catch (System.IndexOutOfRangeException e)
                        { }
                        try
                        {
                            num[i, j + 1] = num[i, j + 1] + 1;
                        }
                        catch (System.IndexOutOfRangeException e)
                        { }
                        try
                        {
                            num[i + 1, j - 1] = num[i + 1, j - 1] + 1;
                        }
                        catch (System.IndexOutOfRangeException e)
                        { }
                        try
                        {
                            num[i + 1, j] = num[i + 1, j] + 1;
                        }
                        catch (System.IndexOutOfRangeException e)
                        { }
                        try
                        {
                            num[i + 1, j + 1] = num[i + 1, j + 1] + 1;
                        }
                        catch (System.IndexOutOfRangeException e)
                        { }
                    }

                }
            }

            for (i = 0; i < input1[0]; i++)
            {
                string res = "";
                for (j = 0; j < input1[1]; j++)
                {
                    if (num[i, j].StartsWith("#"))
                    {
                        num[i, j] = "#";
                    }
                    else 
                    {
                        num[i, j] = num[i, j].ToCharArray().Select(x => int.Parse(x.ToString())).Sum().ToString();
                    }
                    res = res+num[i, j];
                }
                Console.WriteLine(res);
            }

                
            

        }

       

    }
}


Measured memory_bytes: 13624