import std;

alias sread = () => readln.chomp();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    long h, w;
    scan(h, w);
    auto s = new string[](h);
    foreach (i; 0 .. h)
    {
        s[i] = sread();

    }
    // writeln(s);
    auto ans = new long[][](h, w);
    // writeln(ans);
    long[] moves = [-1, 0, 1];

    foreach (i; 0 .. h)
    {
        foreach (j; 0 .. w)
        {
            //8方向見て#のとき+1する
            foreach (y; moves)
            {
                foreach (x; moves)

                {
                    if ((i + y < 0) || (i + y > h - 1) || (j + x < 0) || (j + x > w - 1))
                    {
                        continue;
                    }
                    if (s[i + y][j + x] == '#')
                    {
                        ans[i][j] += 1;
                    }
                }

            }
        }
    }
    // writeln(ans);
    foreach (i; 0 .. h)
    {
        foreach (j; 0 .. w)
        {
            if (s[i][j] == '.')
            {
                write(ans[i][j]);
            }
            else
            {
                write('#');
            }

        }
        writeln();
    }
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}
