from sys import stdin

import numpy as np

input = stdin.readline

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

s = (np.array([list(input().strip()) for _ in range(h)])=="#")

ans = np.zeros((h+2,w+2),dtype=np.uint8)

for i,j in [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]:

  ans[1+i:h+1+i,1+j:w+1+j] += s

ans = ans[1:h+1,1:w+1].astype("str")

ans[s] = "#"

for i in ans:

  print(("".join(i)))
def main():

  from sys import stdin

  input = stdin.readline

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

  s = []

  sa = s.append

  sa(list("."*(w+2)))

  for _ in range(h):

    sa(["."]+list(input().strip())+["."])

  sa(list("."*(w+2)))

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

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

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

        n = 0

        n += s[i-1][j-1:j+2].count("#")

        n += s[i][j-1:j+2].count("#")

        n += s[i+1][j-1:j+2].count("#")

        s[i][j] = str(n)

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

    print(("".join(s[i][1:w+1])))

main()
from sys import stdin
import numpy as np

input = stdin.readline
h, w = list(map(int, input().split()))
s = np.array([list(input().strip()) for _ in range(h)]) == "#"
ans = np.zeros((h + 2, w + 2), dtype=np.uint8)
for i, j in [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]:
    ans[1 + i : h + 1 + i, 1 + j : w + 1 + j] += s
ans = ans[1 : h + 1, 1 : w + 1].astype("str")
ans[s] = "#"
for i in ans:
    print(("".join(i)))

def main():
    from sys import stdin

    input = stdin.readline
    h, w = list(map(int, input().split()))
    s = []
    sa = s.append
    sa(list("." * (w + 2)))
    for _ in range(h):
        sa(["."] + list(input().strip()) + ["."])
    sa(list("." * (w + 2)))
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if s[i][j] == ".":
                n = 0
                n += s[i - 1][j - 1 : j + 2].count("#")
                n += s[i][j - 1 : j + 2].count("#")
                n += s[i + 1][j - 1 : j + 2].count("#")
                s[i][j] = str(n)
    for i in range(1, h + 1):
        print(("".join(s[i][1 : w + 1])))


main()

-from sys import stdin -import numpy as np +def main(): +    from sys import stdin -input = stdin.readline -h, w = list(map(int, input().split())) -s = np.array([list(input().strip()) for _ in range(h)]) == "#" -ans = np.zeros((h + 2, w + 2), dtype=np.uint8) -for i, j in [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]: -    ans[1 + i : h + 1 + i, 1 + j : w + 1 + j] += s -ans = ans[1 : h + 1, 1 : w + 1].astype("str") -ans[s] = "#" -for i in ans: -    print(("".join(i))) +    input = stdin.readline +    h, w = list(map(int, input().split())) +    s = [] +    sa = s.append +    sa(list("." * (w + 2))) +    for _ in range(h): +        sa(["."] + list(input().strip()) + ["."]) +    sa(list("." * (w + 2))) +    for i in range(1, h + 1): +        for j in range(1, w + 1): +            if s[i][j] == ".": +                n = 0 +                n += s[i - 1][j - 1 : j + 2].count("#") +                n += s[i][j - 1 : j + 2].count("#") +                n += s[i + 1][j - 1 : j + 2].count("#") +                s[i][j] = str(n) +    for i in range(1, h + 1): +        print(("".join(s[i][1 : w + 1]))) + + +main()