import sys

from collections import deque



h, w = (int(x) for x in sys.stdin.readline().split())

strings = deque(sys.stdin.read().split())



for i in range(h):

    strings[i] = ''.join(['-', strings[i], '-'])

strings.append('-' * (w + 2)); strings.appendleft('-' * (w + 2))



ans = []

for i in range(1, h + 1):

    s = ''

    for j in range(1, w + 1):

        current = strings[i][j]

        if current == '#': s += '#'

        elif current == '.':

            count = 0

            for t in range(i-1, i+2):

                for u in range(j-1, j+2):

                    if strings[t][u] == '#': count += 1

            s += str(count)

    ans.append(s)



for s in ans: print(s)



import sys



h, w = map(int, sys.stdin.readline().split())

canvas = ['.' * (w + 2)] + ['.' + sys.stdin.readline().rstrip() + '.' for _ in range(h)] + ['.' * (w + 2)]





def main():

    res = [[0] * (w + 1) for _ in range(h + 1)]

    for i in range(1, h + 1):

        for j in range(1, w + 1):

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

                res[i][j] = '#'

                continue

            for di in range(-1, 2):

                for dj in range(-1, 2):

                    y = i + di

                    x = j + dj

                    if canvas[y][x] == '#':

                        res[i][j] += 1

    

    for i in range(1, h+1):

        yield ''.join(list(map(str, res[i][1:])))



if __name__ == '__main__':

    ans = main()

    print(*ans, sep='\n')

import sys
from collections import deque

h, w = (int(x) for x in sys.stdin.readline().split())
strings = deque(sys.stdin.read().split())
for i in range(h):
    strings[i] = "".join(["-", strings[i], "-"])
strings.append("-" * (w + 2))
strings.appendleft("-" * (w + 2))
ans = []
for i in range(1, h + 1):
    s = ""
    for j in range(1, w + 1):
        current = strings[i][j]
        if current == "#":
            s += "#"
        elif current == ".":
            count = 0
            for t in range(i - 1, i + 2):
                for u in range(j - 1, j + 2):
                    if strings[t][u] == "#":
                        count += 1
            s += str(count)
    ans.append(s)
for s in ans:
    print(s)

import sys

h, w = map(int, sys.stdin.readline().split())
canvas = (
    ["." * (w + 2)]
    + ["." + sys.stdin.readline().rstrip() + "." for _ in range(h)]
    + ["." * (w + 2)]
)


def main():
    res = [[0] * (w + 1) for _ in range(h + 1)]
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if canvas[i][j] == "#":
                res[i][j] = "#"
                continue
            for di in range(-1, 2):
                for dj in range(-1, 2):
                    y = i + di
                    x = j + dj
                    if canvas[y][x] == "#":
                        res[i][j] += 1
    for i in range(1, h + 1):
        yield "".join(list(map(str, res[i][1:])))


if __name__ == "__main__":
    ans = main()
    print(*ans, sep="\n")

-from collections import deque -h, w = (int(x) for x in sys.stdin.readline().split()) -strings = deque(sys.stdin.read().split()) -for i in range(h): -    strings[i] = "".join(["-", strings[i], "-"]) -strings.append("-" * (w + 2)) -strings.appendleft("-" * (w + 2)) -ans = [] -for i in range(1, h + 1): -    s = "" -    for j in range(1, w + 1): -        current = strings[i][j] -        if current == "#": -            s += "#" -        elif current == ".": -            count = 0 -            for t in range(i - 1, i + 2): -                for u in range(j - 1, j + 2): -                    if strings[t][u] == "#": -                        count += 1 -            s += str(count) -    ans.append(s) -for s in ans: -    print(s) +h, w = map(int, sys.stdin.readline().split()) +canvas = ( +    ["." * (w + 2)] +    + ["." + sys.stdin.readline().rstrip() + "." for _ in range(h)] +    + ["." * (w + 2)] +) + + +def main(): +    res = [[0] * (w + 1) for _ in range(h + 1)] +    for i in range(1, h + 1): +        for j in range(1, w + 1): +            if canvas[i][j] == "#": +                res[i][j] = "#" +                continue +            for di in range(-1, 2): +                for dj in range(-1, 2): +                    y = i + di +                    x = j + dj +                    if canvas[y][x] == "#": +                        res[i][j] += 1 +    for i in range(1, h + 1): +        yield "".join(list(map(str, res[i][1:]))) + + +if __name__ == "__main__": +    ans = main() +    print(*ans, sep="\n")