h, w = list(map(int, input().split()))

s = [list(eval(input())) for _ in range(h)]

for i in range(h):

    ans = []

    for j in range(w):

        bomb = 0

        if s[i][j] == ".":

            for k in [0, -1, 1]:

                for n in [0, -1, 1]:

                    if i + k < h and j + n < w:

                        if i + k < 0 or j + n < 0:

                            continue

                        if s[i + k][j + n] == "#":

                            bomb += 1

            ans.append(str(bomb))

        else:

            ans.append("#")

    print(("".join(ans)))
h, w = list(map(int, input().split()))

s = [list(eval(input())) for i in range(h)]

for i in range(h):

    T = ""

    for j in range(w):

        if s[i][j] == ".":

            count = 0

            if i < h - 1:

                if s[i + 1][j] == "#":

                    count += 1

                if j < w - 1:

                    if s[i + 1][j + 1] == "#":

                        count += 1

                if j > 0:

                    if s[i + 1][j - 1] == "#":

                        count += 1

            if i > 0:

                if s[i - 1][j] == "#":

                    count += 1

                if j < w - 1:

                    if s[i - 1][j + 1] == "#":

                        count += 1

                if j > 0:

                    if s[i - 1][j - 1] == "#":

                        count += 1

            if j < w - 1:

                if s[i][j + 1] == "#":

                    count += 1

            if j > 0:

                if s[i][j - 1] == "#":

                    count += 1

            T += str(count)

        else:

            T += "#"

    print(T)
h, w = list(map(int, input().split()))
s = [list(eval(input())) for _ in range(h)]
for i in range(h):
    ans = []
    for j in range(w):
        bomb = 0
        if s[i][j] == ".":
            for k in [0, -1, 1]:
                for n in [0, -1, 1]:
                    if i + k < h and j + n < w:
                        if i + k < 0 or j + n < 0:
                            continue
                        if s[i + k][j + n] == "#":
                            bomb += 1
            ans.append(str(bomb))
        else:
            ans.append("#")
    print(("".join(ans)))

h, w = list(map(int, input().split()))
s = [list(eval(input())) for i in range(h)]
for i in range(h):
    T = ""
    for j in range(w):
        if s[i][j] == ".":
            count = 0
            if i < h - 1:
                if s[i + 1][j] == "#":
                    count += 1
                if j < w - 1:
                    if s[i + 1][j + 1] == "#":
                        count += 1
                if j > 0:
                    if s[i + 1][j - 1] == "#":
                        count += 1
            if i > 0:
                if s[i - 1][j] == "#":
                    count += 1
                if j < w - 1:
                    if s[i - 1][j + 1] == "#":
                        count += 1
                if j > 0:
                    if s[i - 1][j - 1] == "#":
                        count += 1
            if j < w - 1:
                if s[i][j + 1] == "#":
                    count += 1
            if j > 0:
                if s[i][j - 1] == "#":
                    count += 1
            T += str(count)
        else:
            T += "#"
    print(T)

-s = [list(eval(input())) for _ in range(h)] +s = [list(eval(input())) for i in range(h)] -    ans = [] +    T = "" -        bomb = 0 -            for k in [0, -1, 1]: -                for n in [0, -1, 1]: -                    if i + k < h and j + n < w: -                        if i + k < 0 or j + n < 0: -                            continue -                        if s[i + k][j + n] == "#": -                            bomb += 1 -            ans.append(str(bomb)) +            count = 0 +            if i < h - 1: +                if s[i + 1][j] == "#": +                    count += 1 +                if j < w - 1: +                    if s[i + 1][j + 1] == "#": +                        count += 1 +                if j > 0: +                    if s[i + 1][j - 1] == "#": +                        count += 1 +            if i > 0: +                if s[i - 1][j] == "#": +                    count += 1 +                if j < w - 1: +                    if s[i - 1][j + 1] == "#": +                        count += 1 +                if j > 0: +                    if s[i - 1][j - 1] == "#": +                        count += 1 +            if j < w - 1: +                if s[i][j + 1] == "#": +                    count += 1 +            if j > 0: +                if s[i][j - 1] == "#": +                    count += 1 +            T += str(count) -            ans.append("#") -    print(("".join(ans))) +            T += "#" +    print(T)