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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve.Answer();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var hw = IO.ReadSplitInt;
            char[][] map = new char[hw[0]][];

            for (int i = 0; i < hw[0]; i++)
            {
                map[i] = ReadLine().ToCharArray();
            }

            for (int i = 0; i < hw[0]; i++)
            {
                for (int j = 0; j < hw[1]; j++)
                {
                    if (map[i][j] == '#') continue;

                    int cnt = 0;

                    if (i != 0)
                    {
                        if (j != 0)
                        {
                            if (map[i - 1][j - 1] == '#') cnt++;
                        }
                        if (map[i - 1][j] == '#') cnt++;
                        if (j != hw[1] - 1)
                        {
                            if (map[i - 1][j + 1] == '#') cnt++;
                        }
                    }
                    if (j != 0)
                    {
                        if (map[i][j - 1] == '#') cnt++;
                    }
                    if (j != hw[1] - 1)
                    {
                        if (map[i][j + 1] == '#') cnt++;
                    }
                    if (i != hw[0] - 1)
                    {
                        if (j != 0)
                        {
                            if (map[i + 1][j - 1] == '#') cnt++;
                        }
                        if (map[i + 1][j] == '#') cnt++;
                        if (j != hw[1] - 1)
                        {
                            if (map[i + 1][j + 1] == '#') cnt++;
                        }
                    }
                    map[i][j] = (char)(cnt + '0');
                }
            }
            for (int i = 0; i < hw[0]; i++)
            {
                for (int j = 0; j < hw[1]; j++)
                {
                    Write(map[i][j]);
                }
                if (i != hw[0] - 1) WriteLine();
            }
        }

        public class IO
        {
            #region Input
            public static string ReadString => ReadLine();
            public static int ReadInt => int.Parse(ReadLine());
            public static long ReadLong => long.Parse(ReadLine());
            public static double ReadDouble => double.Parse(ReadLine());

            public static List<string> ReadSplitString => ReadLine().Split().ToList();
            public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList();
            public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList();
            public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList();
            #endregion

            #region Output
            public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
            public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");

            #endregion
        }

        public class Mod
        {
            #region
            private readonly static long M = 1000000007;

            public static long Add(long a, long b) => (a * b) % M;
            public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
            public static long Multi(long a, long b) => (a * b) % M;
            #endregion
        }

        public static long GCD(long x, long y)
        {
            #region
            if (x < y)
            {
                var tmp = x;
                x = y;
                y = tmp;
            }
            while (true)

            {
                if (x % y == 0)
                {
                    return y;
                }
                else
                {
                    var tmp = x;
                    x = y;
                    y = tmp % y;
                }
            }
            #endregion
        }

        public static long Choice2(long n)
        {
            #region
            if (n <= 1)
                return 0;
            if (n == 2)
                return 1;
            else
                return n * (n - 1) / 2;
            #endregion
        }
    }
}

Measured memory_bytes: 13396