using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.ReadLine();
        }

        public void Solve(ConsoleInput cin)
        {
            int l = cin.ReadInt;
            int c = cin.ReadInt;
            string[,] map = new string[l,c];

            for (int i = 0; i < l; i++)
            {
                var line = cin.ReadLine.ToCharArray();
                for (int j = 0; j < c; j++)
                    map[i, j] = line[j].ToString();
            }

            for (int i = 0; i < l; i++)
                for (int j = 0; j < c; j++)
                {
                    if (map[i, j] == "#") continue;

                    int cnt = 0;
                    if (i - 1 >= 0 && j - 1 >= 0 && map[i - 1, j - 1] == "#") cnt++;
                    if (i - 1 >= 0 && j - 0 >= 0 && map[i - 1, j - 0] == "#") cnt++;
                    if (i - 1 >= 0 && j + 1 < c && map[i - 1, j + 1] == "#") cnt++;
                    if (i - 0 >= 0 && j - 1 >= 0 && map[i - 0, j - 1] == "#") cnt++;
                    if (i - 0 >= 0 && j + 1 < c && map[i - 0, j + 1] == "#") cnt++;
                    if (i + 1 < l && j - 1 >= 0 && map[i + 1, j - 1] == "#") cnt++;
                    if (i + 1 < l && j - 0 >= 0 && map[i + 1, j - 0] == "#") cnt++;
                    if (i + 1 < l && j + 1 < c && map[i + 1, j + 1] == "#") cnt++;

                    map[i, j] = cnt.ToString();
                }

            for (int i = 0; i < l; i++)
            {
                for (int j = 0; j < c; j++)
                {
                    Console.Write(map[i, j]);
                }
                Console.WriteLine();
            }
        }


    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long num) { var ret = new string[num]; for (long i = 0; i < num; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long num) { var ret = new int[num]; for (long i = 0; i < num; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long num) { var ret = new long[num]; for (long i = 0; i < num; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13396