using System;
using System.Collections.Generic;
using System.Linq;

class Solution
{
    static int h;
    static int w;

    static int Count(char[][] field, int x, int y)
    {
        int count = 0;
        for (int xx = x - 1; xx <= x + 1; xx++)
        {
            for (int yy = y - 1; yy <= y + 1; yy++)
            {
                if (0 <= xx && xx < w && 0 <= yy && yy < h)
                {
                    if (field[yy][xx] == '#')
                    {
                        count++;
                    }
                }
            }
        }
        return count;
    }

    static void Solve(char[][] field)
    {
        for (int y = 0; y < h; y++)
        {
            for (int x = 0; x < w; x++)
            {
                if (field[y][x] == '.')
                {
                    var count = Count(field, x, y);
                    if (count > 0)
                    {
                        field[y][x] = count.ToString()[0];
                    }
                }
            }
        }
    }

    static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        h = vals[0];
        w = vals[1];

        var field = new char[h][];
        for (int i = 0; i < h; i++)
        {
            field[i] = Console.ReadLine().ToCharArray();
        }
        Solve(field);

        for (int i = 0; i < h; i++)
        {
            Console.WriteLine(new string(field[i]));
        }
    }
}