from itertools import product

H, W = list(map(int, input().split()))

S = [input() for _ in range(H)]

ans = S[:]

ans = [list(a) for a in ans]

S = ['.' * (W + 2)] + ['.' + s + '.' for s in S] + ['.' * (W + 2)]

for h, w in product(range(1, H + 1), range(1, W + 1)):

    if S[h][w] == '#':

        continue

    count = 0

    for i, j in product(range(h - 1, h + 2), range(w - 1, w + 2)):

        if (i == h) and (j == w):

            continue

        if S[i][j] == '#':

            count += 1

    ans[h - 1][w - 1] = str(count)

ans = [''.join(a) for a in ans]

[print(a) for a in ans]

from itertools import product

H, W = list(map(int, input().split()))

S = [['.'] * (W + 2)] + [['.', ] + list(input()) + ['.', ] for _ in range(H)] + [['.'] * (W + 2)]

ans = [[0] * W for _ in range(H)]

for i, j in product(range(1, H + 1), range(1, W + 1)):

    if S[i][j] == '.':

        count = 0

        for k, l in product(range(i - 1, i + 2), range(j - 1, j + 2)):

            if k == i and l == j:

                continue

            elif S[k][l] == '#':

                count += 1

        ans[i - 1][j - 1] = str(count)

    else:

        ans[i - 1][j - 1] = '#'

[print(''.join(a)) for a in ans]

from itertools import product

H, W = list(map(int, input().split()))
S = [input() for _ in range(H)]
ans = S[:]
ans = [list(a) for a in ans]
S = ["." * (W + 2)] + ["." + s + "." for s in S] + ["." * (W + 2)]
for h, w in product(range(1, H + 1), range(1, W + 1)):
    if S[h][w] == "#":
        continue
    count = 0
    for i, j in product(range(h - 1, h + 2), range(w - 1, w + 2)):
        if (i == h) and (j == w):
            continue
        if S[i][j] == "#":
            count += 1
    ans[h - 1][w - 1] = str(count)
ans = ["".join(a) for a in ans]
[print(a) for a in ans]

from itertools import product

H, W = list(map(int, input().split()))
S = (
    [["."] * (W + 2)]
    + [
        [
            ".",
        ]
        + list(input())
        + [
            ".",
        ]
        for _ in range(H)
    ]
    + [["."] * (W + 2)]
)
ans = [[0] * W for _ in range(H)]
for i, j in product(range(1, H + 1), range(1, W + 1)):
    if S[i][j] == ".":
        count = 0
        for k, l in product(range(i - 1, i + 2), range(j - 1, j + 2)):
            if k == i and l == j:
                continue
            elif S[k][l] == "#":
                count += 1
        ans[i - 1][j - 1] = str(count)
    else:
        ans[i - 1][j - 1] = "#"
[print("".join(a)) for a in ans]

-S = [input() for _ in range(H)] -ans = S[:] -ans = [list(a) for a in ans] -S = ["." * (W + 2)] + ["." + s + "." for s in S] + ["." * (W + 2)] -for h, w in product(range(1, H + 1), range(1, W + 1)): -    if S[h][w] == "#": -        continue -    count = 0 -    for i, j in product(range(h - 1, h + 2), range(w - 1, w + 2)): -        if (i == h) and (j == w): -            continue -        if S[i][j] == "#": -            count += 1 -    ans[h - 1][w - 1] = str(count) -ans = ["".join(a) for a in ans] -[print(a) for a in ans] +S = ( +    [["."] * (W + 2)] +    + [ +        [ +            ".", +        ] +        + list(input()) +        + [ +            ".", +        ] +        for _ in range(H) +    ] +    + [["."] * (W + 2)] +) +ans = [[0] * W for _ in range(H)] +for i, j in product(range(1, H + 1), range(1, W + 1)): +    if S[i][j] == ".": +        count = 0 +        for k, l in product(range(i - 1, i + 2), range(j - 1, j + 2)): +            if k == i and l == j: +                continue +            elif S[k][l] == "#": +                count += 1 +        ans[i - 1][j - 1] = str(count) +    else: +        ans[i - 1][j - 1] = "#" +[print("".join(a)) for a in ans]