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

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            String S1 = Console.ReadLine();
            String[] L1 = S1.Split(' ');
            int H = int.Parse(L1[0]);
            int W = int.Parse(L1[1]);

            String[] S = new string[H];
            for(int i=0; i<H; i++)
            {
                S[i] = Console.ReadLine();
            }

            Char[,] ans = new char[H,W];

            for(int i=0; i<H; i++)
            {
                for(int j=0; j<W; j++)
                {
                    if(S[i][j] == '#')
                    {
                        ans[i, j] = '#';
                    }
                    else
                    {
                        int count = 0;
                        if(i != 0)
                        {
                            if(j != 0)
                            {
                                if (S[i - 1][j - 1] == '#')
                                {
                                    count++;
                                }
                            }
                            if (S[i - 1][j] == '#')
                            {
                                count++;
                            }
                            if(j != W - 1)
                            {
                                if (S[i - 1][j + 1] == '#')
                                {
                                    count++;
                                }
                            }
                        }
                        if(j != 0)
                        {
                            if (S[i][j - 1] == '#')
                            {
                                count++;
                            }
                        }
                        if (j != W - 1)
                        {
                            if (S[i][j + 1] == '#')
                            {
                                count++;
                            }
                        }
                        if (i != H - 1)
                        {
                            if (j != 0)
                            {
                                if (S[i + 1][j - 1] == '#')
                                {
                                    count++;
                                }
                            }
                            if (S[i + 1][j] == '#')
                            {
                                count++;
                            }
                            if (j != W - 1)
                            {
                                if (S[i + 1][j + 1] == '#')
                                {
                                    count++;
                                }
                            }
                        }
                        ans[i, j] = count.ToString()[0];
                    }
                }
            }

            for(int i=0; i<H; i++)
            {
                for(int j=0; j<W; j++)
                {
                    Console.Write(ans[i, j]);
                }
                Console.WriteLine();
            }

        }
    }
}

Measured memory_bytes: 13140