import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    long h, w;
    scan(h, w);
    auto field = new string[](h);
    foreach (ref e; field)
        e = sread();

    auto box = new long[][](h, w);
    auto x_move = [-1, 0, 1];
    auto y_move = [-1, 0, 1];
    foreach (i; iota(h))
    {
        foreach (j; iota(w))
        {
            foreach (k; y_move)
            {
                if (i + k < 0 || i + k >= h)
                    continue;

                foreach (l; x_move)
                {
                    if (j + l < 0 || j + l >= w)
                        continue;

                    // writefln("%s %s, %s %s", i, j, k, l);
                    box[i][j] += (field[i + k][j + l] == '#').to!long;
                }
            }
        }
    }
    foreach (i, e; field)
    {
        foreach (j, f; e)
        {
            if (f == '#')
                write("#");
            else
                write(box[i][j]);
        }
        writeln();
    }

}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}
